Example #1
0
  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());
    }
  }
Example #2
0
 public void play(int startingTurn) {
   turn = startingTurn;
   switchTurns();
   while (running) {
     switchTurns();
     Command command = parser.getCommand();
     running = processCommand(command);
   }
 }