private boolean place(Command command) { if (!command.hasSecondWord() || !command.hasThirdWord()) { System.out.println("Please enter a valid position"); return true; } int x = Integer.parseInt(command.getSecondWord()); int y = Integer.parseInt(command.getThirdWord()); Position pos = new Position(x, y); Piece piece = null; if (validMove(pos)) { if (turn == X) { piece = new X(); } else if (turn == O) { piece = new O(); } board.addPiece(pos, piece); view.update(board); view.display(); return checkGameStatus(pos); } else { System.out.println("Invalid Position"); return place(parser.getCommand()); } }
// Recebe a entrada (input) e envia ao parser para que este determine qual o tipo do comando // (CommandUse ou CommandPath) public void execute(String command) throws ParserConfigurationException, SAXException, IOException, SQLException, ClassNotFoundException { Parser parser = new Parser(); parser.setCommand(command.trim()); this.execute(parser.getCommand()); }
public void play(int startingTurn) { turn = startingTurn; switchTurns(); while (running) { switchTurns(); Command command = parser.getCommand(); running = processCommand(command); } }
public void play() { printWelcome(); boolean finished = false; while (!finished) { Command command = parser.getCommand(); finished = processCommand(command); } System.out.println("Thank you for playing. Good bye."); }
/** Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main command loop. Here we repeatedly read commands and // execute them until the game is over. boolean finished = false; while (!finished) { Command command = parser.getCommand(); finished = processCommand(command); } System.out.println("Thank you for playing. Good bye."); }