/** * Overrides World<T> newGame(char). Shoots a MoveInfo with null piece and null location to the * CheckerGame if the game is still running. If the game has ended, directly changes the * CheckerGame's game status for CheckerRunner to detect. * * @param a the new game status */ public void newGame(char a) { newGame = a; playerPiece = null; setPlayerLocation(null); if (!lock.hasQueuedThreads()) // if the game has ended { game.newGame(a); } super.newGame(); // World's newGame() disposes the frame }
/** * Handles the mouse location click. * * @param loc the location that was clicked * @return true because the click has been handled */ @Override public boolean locationClicked(Location loc) { if (game.getTurn() instanceof SmartComputerCheckerPlayer) // ignore all clicks on CPU's turn { return true; } if (lastMove != null && lastMove.isJump() && lastMove.getPiece().canJump()) // locks selection onto jump-chaining piece { Piece lastPiece = lastMove.getPiece(); if (!loc.equals(lastPiece.getLocation()) && !lastPiece.getAllowedMoves().contains(loc)) // consumes irrelevant clicks { return true; } } if (getGrid().get(loc) != null && !(getGrid().get(loc) instanceof PieceTile)) { Piece p = getGrid().get(loc); if (pieceSelected) { game.undisplayMoves(playerPiece); } game.displayMoves(p); // selection and highlight available moves playerPiece = p; pieceSelected = true; } else if (pieceSelected && !playerPiece.getAllowedMoves().contains(loc)) { pieceSelected = false; game.undisplayMoves(playerPiece); // undo selection and highlight playerPiece = null; } else if (pieceSelected && playerPiece.getAllowedMoves().contains(loc)) { pieceSelected = false; game.undisplayMoves(playerPiece); // undo selection and highlight setPlayerLocation(loc); } return true; }