예제 #1
0
  /**
   * This method takes an event, and sends the appropriate commands to the model based on the
   * command that the event sends:
   *
   * @param event an actionEvent representing an instruction from the View.
   */
  public void actionPerformed(ActionEvent event) {
    gameBoard = Board.getBoard();
    gameInfo = GameInfoPanel.getGameInfo();

    String actionCommand = event.getActionCommand();

    // play button commands
    if (actionCommand.equals("play")) {
      /** this is passed in as an ActionListener */
      if (!hasStarted) {
        makeGameThread();
        waitTime = DEFAULT_RUN;
        hasStarted = true;
        isFinished = model.isFinished();
      } else {
        paused = false;
        waitTime = DEFAULT_RUN;
      }
    }

    // fastforward button commands
    if (actionCommand.equals("fastForward")) {
      paused = false;
      waitTime = FAST_FORWARD;
    }

    // fastforwardX2 button commands
    if (actionCommand.equals("fastForwardX2")) {
      paused = false;
      waitTime = DOUBLE_FAST_FORWARD;
    }

    // pause button commands (pause game until user runs some sort of play
    if (actionCommand.equals("pause")) {
      paused = true;
    }

    // stop game
    if (actionCommand.equals("stop")) {
      gameStopped = true;
    }

    // handle stepback button
    if (actionCommand.equals("home")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
    // handle stepback button
    if (actionCommand.equals("stepback")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
  }