Skip to content

Commit

Permalink
Merge pull request #56 from schanes13/feature/GAMES_000J
Browse files Browse the repository at this point in the history
Feature/GAMES_000J
  • Loading branch information
glocka authored Jun 3, 2020
2 parents 720a3d9 + fbaeb86 commit d83853c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
28 changes: 13 additions & 15 deletions app/src/androidTest/java/com/swt20/swt_morning2/HangmanTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ public void playGame() {
}
assertThat(st.getScore(Game.HANGMAN), is(oldScore + 1));
return;
} catch (Exception e) {
} catch (AssertionError e) {
// View not displayed
}
}
assert (false);
}



@Test
public void playGameTwice() {

Expand All @@ -102,7 +104,7 @@ public void playGameTwice() {
} else {
return;
}
} catch (Exception e) {
} catch (AssertionError e) {
// View not displayed
}
}
Expand All @@ -119,7 +121,7 @@ public void pressWrongLetterTwice() {
// Go from Hangman Menu to Game
onView(withId(R.id.hangmanStartGameButton)).perform(click());

String letter = "y";
String letter = ".";

for (int i = 0; i < 2; i++) {
onView(withId(R.id.plainText_nextChar)).perform(typeText(letter));
Expand All @@ -133,7 +135,7 @@ public void pressWrongLetterTwice() {
matches(withDrawable(R.drawable.hangman_1)));
return;
// View displayed
} catch (Exception e) {
} catch (AssertionError e) {
// View not displayed
}
}
Expand All @@ -149,20 +151,15 @@ public void pressLetterMoreThanNineTimes() {
// Go from Hangman Menu to Game
onView(withId(R.id.hangmanStartGameButton)).perform(click());

String letter = "a";
String letter = ".";

for (int i = 0; i < 12; i++) {
onView(withId(R.id.plainText_nextChar)).perform(typeText(letter));
try {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// View not displayed
}
onView(withId(R.id.button_playagain)).check(matches(isDisplayed()));
return;
// View displayed
} catch (Exception e) {
} catch (AssertionError e) {
// View not displayed
}
}
Expand Down Expand Up @@ -262,6 +259,7 @@ public void doubleAddCustomWord() {

}

@Test
public void scoreReduced() {
Activity activity = activityRule.getActivity();
ScoreTracker st = new ScoreTracker(activity.getApplicationContext());
Expand All @@ -272,8 +270,8 @@ public void scoreReduced() {

// Go from Hangman Menu to Game
onView(withId(R.id.hangmanStartGameButton)).perform(click());
String letter = "a";
for (int i = 0; i <= 9; i++) {
String letter = ".";
for (int i = 0; i <= 12; i++) {
onView(withId(R.id.plainText_nextChar)).perform(typeText(letter));
try {
onView(withId(R.id.button_playagain)).check(matches(isDisplayed()));
Expand All @@ -282,12 +280,12 @@ public void scoreReduced() {
onView(isRoot()).perform(pressBack());
// View displayed
break;
} catch (Exception e) {
} catch (AssertionError e) {
// View not displayed
}
}
try {
Thread.sleep(5000);
Thread.sleep(100);
} catch (InterruptedException e) {
// View not displayed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,26 @@ private boolean clickField(int rid, int colourid) {
try {
onView(withId(rid)).check(matches(
EspressoTestsMatchers.withDrawable(R.drawable.empty)));
} catch (Error e) {
} catch (Throwable e) {
// Not empty -- continue
return false;
}

onView(withId(rid)).perform(click());
onView(withId(rid)).check(matches(EspressoTestsMatchers.withDrawable(colourid)));
try {
onView(withId(rid)).perform(click());
try {
if (onView(withId(R.id.ttt_menu_button)) != null) {
onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed()));
}
return false;
} catch (Throwable e) {
//empty
}
onView(withId(rid)).check(matches(EspressoTestsMatchers.withDrawable(colourid)));
} catch (Throwable e) {
onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed()));
return false;
}
return true;
}

Expand Down Expand Up @@ -250,4 +263,29 @@ public void autoplayerExists() {
}
}
}

@Test
public void playToDraw() {
onView(withId(R.id.ticTacToeButton)).perform(click());
onView(withId(R.id.ttt_menu_button)).perform(click());
onView(withId(R.id.imageView)).perform(click());
onView(withId(R.id.imageView7)).perform(click());
onView(withId(R.id.imageView8)).perform(click());
onView(withId(R.id.imageView3)).perform(click());
onView(withId(R.id.imageView2)).perform(click());
onView(withId(R.id.imageView9)).perform(click());
onView(withId(R.id.imageView6)).perform(click());
onView(withId(R.id.imageView5)).perform(click());
onView(withId(R.id.imageView4)).perform(click());
try {
onView(withId(R.id.ttt_menu_button)).check(matches(isDisplayed()));
} catch (Exception e) {
assert (true);
return;
}
assert (false);

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ public void onClick(View view) {
for (int i = 0; i < word2guess.length(); i++) {
word2guessViewtext += "_ ";
}
textViewWord2Guess.setVisibility(View.VISIBLE);
textViewWord2Guess.setText(word2guessViewtext);
textView.setVisibility(View.VISIBLE);
nextChar.setVisibility(View.VISIBLE);

view.findViewById(R.id.button_playagain).setVisibility(View.INVISIBLE);
feedbackView.setImageResource(0);
mainView.findViewById(R.id.button_hangman_hint).setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -221,7 +223,7 @@ private void gameFinished(int points, String text, View view) {
textView.setVisibility(View.INVISIBLE);
nextChar.setVisibility(View.INVISIBLE);
view.findViewById(R.id.button_hangman_hint).setVisibility(View.INVISIBLE);

textViewWord2Guess.setVisibility(View.INVISIBLE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void setupCell(final int x, final int y, final ImageView imageView,
final TableLayout gameField) {
imageView.setImageResource(R.drawable.empty);
imageView.setOnClickListener(new View.OnClickListener() {
private void checkWin() {
private boolean checkWin() {
TicTacToeGameLogic.Player winner = logic.getWinner();
if (winner != null) {
String text;
Expand All @@ -77,7 +77,9 @@ private void checkWin() {
logic.changeScore(winner, tracker);
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
getActivity().onBackPressed();
return true;
}
return false;
}

@Override
Expand All @@ -86,7 +88,9 @@ public void onClick(View view) {

// outsource to fkt.
imageView.setImageResource(logic.getCell(x, y).getOwner().getResId());
checkWin();
if (checkWin()) {
return;
}
logic.autoplayerTurn();
for (int y = 0; y < gameField.getChildCount(); y++) {
final TableRow currentRow = (TableRow) gameField.getChildAt(y);
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/layout/hangman_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
android:layout_height="wrap_content"
android:text="@string/hangman_playagain"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_word2guess"
app:layout_constraintVertical_bias="0.482" />
app:layout_constraintTop_toBottomOf="@+id/feedbackView" />

<EditText
android:id="@+id/plainText_nextChar"
Expand Down Expand Up @@ -83,7 +81,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hangman_hint_button_text"
app:layout_constraintBottom_toTopOf="@+id/button_playagain"
app:layout_constraintBottom_toTopOf="@+id/plainText_nextChar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_word2guess" />
Expand Down

0 comments on commit d83853c

Please sign in to comment.