Exemplo n.º 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());
    }
  }
Exemplo n.º 2
0
  private boolean processCommand(Command command) {
    switch (command.getCommandWord()) {
      case "quit":
        System.out.println("Thank you for playing!");
        return false;
      case "help":
        System.out.println(words.getCommands());
        return true;
      case "place":
        return place(command);
    }

    return true;
  }