Skip to content

Commit d990794

Browse files
committed
Fixed bug: selecting and then deselecting a tile to clear it would result
in the board being enabled for transfer to the other player even though effectively no turn had been taken.
1 parent 80cb982 commit d990794

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

NFC/TouchTicTacToe/src/nfc/sample/tictactoe/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public interface Constants {
2020

21-
public static final String MYAPP_VERSION = "1.0.1";
21+
public static final String MYAPP_VERSION = "1.0.2";
2222
public static final String MYAPP_NAME = "Touch Tic Tac Toe";
2323

2424
public static final String [] WINNER_MESSAGE = {"YOU HAVE WON!!","Touch devices to start new game"};

NFC/TouchTicTacToe/src/nfc/sample/tictactoe/game/GameState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public void updateTileThisPlayer(int tile, int players_symbol) {
103103
tile_states[tile] = players_symbol;
104104
setUiState(tile, players_symbol, true);
105105
tile_count_this_turn++;
106+
Utilities.log("XXXX updateTileThisPlayer tile_count_this_turn=" + tile_count_this_turn);
106107
_listener.tileChanged(tile);
107108
tile_set = true;
108109
if (hasWon(players_symbol)) {
@@ -126,6 +127,9 @@ public void updateTileThisPlayer(int tile, int players_symbol) {
126127
tile_states[tile] = Constants.TILE_STATE_BLANK;
127128
setUiState(tile, Constants.TILE_STATE_BLANK, true);
128129
tile_set = false;
130+
tile_count_this_turn--;
131+
_listener.tileChanged(tile);
132+
Utilities.log("XXXX updateTileThisPlayer tile_count_this_turn=" + tile_count_this_turn);
129133
} else {
130134
Utilities.log("XXXX updateTileThisPlayer ignoring request as tile contains other player's symbol or is locked from previous turn");
131135
tile_set = false;

NFC/TouchTicTacToe/src/nfc/sample/tictactoe/ui/GameScreen.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,21 @@ public void tileChanged(int tile) {
277277
turn_over.set_tile_changed(tile);
278278
turn_over.set_symbol_played(_symbol);
279279
if(!game_state.isGame_over() && !game_state.isBoardFull()) {
280-
setStatusMessage("Touch devices to pass turn to other player");
280+
Utilities.log("XXXX tileChanged tile_count_this_turn=" + game_state.getTile_count_this_turn());
281281
if(game_state.getTile_count_this_turn() == 1) {
282282
// get ready to send the turn over message when players touch devices again
283+
setStatusMessage("Touch devices to pass turn to other player");
283284
prepTurnOver();
285+
} else {
286+
if(game_state.getTile_count_this_turn() == 0) {
287+
// tile was unset so switch off messaging
288+
try {
289+
proto.disableMessaging();
290+
} catch(NFCException e) {
291+
Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
292+
setStatusMessage("Error: please try again");
293+
}
294+
}
284295
}
285296
}
286297
}

0 commit comments

Comments
 (0)