// pretty printing of Lobby, mainly for debugging purposes public void printLobby() { System.out.format("Lobby has %d / %d players:\n", this.players.size(), this.slots); int i = 1; for (Player player : this.players) { System.out.format("%d: %s\n", i, player.toString()); i++; } }
/** Test of toString method, of class Player. */ @Test public void testToString() { System.out.println("toString"); Player instance = null; String expResult = ""; String result = instance.toString(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** Test of toString method, of class Player. */ @Test public void testToString() { System.out.println("toString"); PlayerInfo pManning = new PlayerInfo("Peyton Manning", 18); int[] alkupaikka1 = {5, 5}; RouteRunner testiOff = new RouteRunner(alkupaikka1, "879987", "Q"); Player qb = new Player(pManning, testiOff); Player instance = qb; String expResult = "18 Peyton Manning"; String result = instance.toString(); assertEquals(expResult, result); }
FFOTesterViewer(FFOTesterController controller, Board board) { this.controller = controller; this.board = board; this.com = new PVS(this, PatternRecognitioner.INSTANCE, 1, 40, 1000000000); TextArea log = controller.log; valueProperty() .addListener( (observable, oldValue, newValue) -> { log.appendText(com.toString()); log.appendText(System.lineSeparator()); log.appendText(newValue.toString()); log.appendText(System.lineSeparator()); completedUpdate = true; }); }
public void print() { System.out.println("Player 1: " + p1.toString()); System.out.println("Player 2: " + p2.toString()); }
public Game( Player playerOne, Player playerTwo, int rows, int columns, String name, String opponentName) { GUIBoard boardYouPlayOn = new GUIBoard(name, rows, columns, 600, 0, 390, 390, 1); GUIBoard oppPlaysThis = new GUIBoard(opponentName, rows, columns, 0, 0, 390, 390, 0); GUIBoard hisHiddenBoard = new GUIBoard(opponentName, rows, columns, 600, 600, 390, 390, 0); GUIBoard yourHiddenBoard = new GUIBoard(name, rows, columns, 0, 600, 390, 390, 1); PriorityBoard pb1 = new PriorityBoard("AI priority Board", rows, columns, 0, 600, 0, 0); PriorityBoard pb2 = new PriorityBoard("AI priority Board", rows, columns, 900, 600, 0, 0); boardYouPlayOn.setPriorityBoard(pb1); yourHiddenBoard.setPriorityBoard(pb2); // this randomizes the boat locations on the boards oppPlaysThis.randomizeBoatPlacement(); hisHiddenBoard.randomizeBoatPlacement(); playerWin = false; playerTwoWin = false; // playerMove gets move from the kill board. Handles null value and cancel button. If player has // already used move area, // this makes move false as well. do { // input loop. Only exits if move input is valid do { do { // playerMove gets move from the kill board. Handles null value and cancel button. If // player has already used move area, // this makes move false as well. try { playerMove = playerOne.getMove(boardYouPlayOn); } catch (NullPointerException e) { int option = JOptionPane.showConfirmDialog( null, "Are your sure you want to quit?", "Confirm Cancel", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { System.exit(0); } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("In"); playerMove = new Move(-1, -1); } if (boardYouPlayOn.getValueAtLocation(playerMove.getRow(), playerMove.getColumn()) == 'H' || boardYouPlayOn.getValueAtLocation(playerMove.getRow(), playerMove.getColumn()) == 'M') { playerMove = new Move(-1, -1); } } while (boardYouPlayOn.getMove(playerMove) == false); // END DO WHILE // assigns char value to opponentBoard if (boardYouPlayOn.getMove(playerMove) == true) { if (hisHiddenBoard.getValueAtLocation(playerMove.getRow(), playerMove.getColumn()) == 'B') { boardYouPlayOn.setValueAtLocation(playerMove.getRow(), playerMove.getColumn(), 'H'); } else { boardYouPlayOn.setValueAtLocation(playerMove.getRow(), playerMove.getColumn(), 'M'); } } aChar = boardYouPlayOn.getValueAtLocation(playerMove.getRow(), playerMove.getColumn()); hisHiddenBoard.setValueAtLocation(playerMove.getRow(), playerMove.getColumn(), aChar); for (int i = 0; i < rows; i++) { for (int k = 0; k < columns; k++) { boardYouPlayOn.twoBoatFound(i, k); } } pb1.setValueAtLocation(playerMove.getRow(), playerMove.getColumn(), aChar); for (int i = 0; i < rows; i++) { for (int k = 0; k < columns; k++) { aChar = boardYouPlayOn.getValueAtLocation(i, k); pb1.changePriority(i, k, aChar); } } hisHiddenBoard.repaintBoard(); boardYouPlayOn.repaintBoard(); // pb1.repaintBoard(); playerWin = boardYouPlayOn.floatingBoat(); } while (boardYouPlayOn.getValueAtLocation(playerMove.getRow(), playerMove.getColumn()) == 'H' && playerWin == false); ////////////// PLAYER 2 /////////////////// // if player misses, its player 2's turn do { // input loop. Only exits if move input is valid do { // playerMove gets move from the kill board. Handles null value and cancel button. If // player has already used move area, // this makes move false as well. playerTwoMove = playerTwo.getMove(yourHiddenBoard); if (yourHiddenBoard.getValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn()) == 'H' || yourHiddenBoard.getValueAtLocation( playerTwoMove.getRow(), playerTwoMove.getColumn()) == 'M') { playerTwoMove = new Move(-1, -1); } } while (yourHiddenBoard.getMove(playerTwoMove) == false); // END DO WHILE // assigns char value to opponentBoard if (yourHiddenBoard.getMove(playerTwoMove) == true) { if (oppPlaysThis.getValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn()) == 'B') { yourHiddenBoard.setValueAtLocation( playerTwoMove.getRow(), playerTwoMove.getColumn(), 'H'); } else { yourHiddenBoard.setValueAtLocation( playerTwoMove.getRow(), playerTwoMove.getColumn(), 'M'); } } aChar = yourHiddenBoard.getValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn()); oppPlaysThis.setValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn(), aChar); pb2.setValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn(), aChar); for (int i = 0; i < rows; i++) { for (int k = 0; k < columns; k++) { aChar = oppPlaysThis.getValueAtLocation(i, k); pb2.changePriority(i, k, aChar); } } oppPlaysThis.repaintBoard(); yourHiddenBoard.repaintBoard(); playerTwoWin = oppPlaysThis.floatingBoat(); } while (yourHiddenBoard.getValueAtLocation(playerTwoMove.getRow(), playerTwoMove.getColumn()) == 'H' && playerTwoWin == false); } while (playerWin == false && playerTwoWin == false); // END MAIN DO WHILE // Win mesage depending on who wins the game if (playerWin) { JOptionPane.showMessageDialog( null, playerOne.toString() + " sunk all the boats! " + playerOne.toString() + " won the game!"); } else { JOptionPane.showMessageDialog( null, playerTwo.toString() + " sunk all the boats!" + playerTwo.toString() + " won the game!"); } } // END GAME
/** Tests for toString. */ @Test public void testToString() { assertThat(player.toString(), is("Player [" + playername + ", " + playername.hashCode() + ']')); }