public GameGUI(GameCanvas theCanvas) {
    super(new BorderLayout());

    this.theCanvas = theCanvas;

    JLabel theTitleLabel = new JLabel(theCanvas.getGameName());
    theTitleLabel.setFont(
        new Font(
            GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()[0],
            Font.BOLD,
            36));

    JPanel northPanel = new JPanel(new FlowLayout());
    northPanel.add(theTitleLabel);

    submitMoveButton = new JButton("Submit Move");
    submitMoveButton.addActionListener(this);

    clearSelectionButton = new JButton("Clear Selection");
    clearSelectionButton.addActionListener(this);

    workingMoveLabel = new JLabel();

    JPanel southCenterPanel = new JPanel(new FlowLayout());
    JPanel southEastPanel = new JPanel(new FlowLayout());
    JPanel southPanel = new JPanel(new BorderLayout());
    southEastPanel.add(new JLabel("Time Remaining     "));
    southEastPanel.add(clearSelectionButton);
    southEastPanel.add(submitMoveButton);
    southPanel.add("West", workingMoveLabel);
    southPanel.add("Center", southCenterPanel);
    southPanel.add("East", southEastPanel);

    add("North", northPanel);
    add("Center", theCanvas);
    add("South", southPanel);

    northPanel.setBackground(theCanvas.getBackground());
    southPanel.setBackground(theCanvas.getBackground());
    southEastPanel.setBackground(theCanvas.getBackground());
    southCenterPanel.setBackground(theCanvas.getBackground());

    theCanvas.addObserver(this);
    updateControls();
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if (gameOver) return;

    if (e.getSource() == clearSelectionButton) {
      theCanvas.clearMoveSelection();
    } else if (e.getSource() == submitMoveButton) {
      if (workingMove != null) {
        moveBeingSubmitted = true;
        updateControls();
        notifyObservers(new MoveSelectedEvent(workingMove));
      }
    }
  }
  private void updateControls() {
    submitMoveButton.setEnabled(!gameOver && !moveBeingSubmitted && !stillMetagaming);
    clearSelectionButton.setEnabled(!gameOver && !moveBeingSubmitted && !stillMetagaming);
    theCanvas.setEnabled(!gameOver && !moveBeingSubmitted && !stillMetagaming);

    if (gameOver) return;
    if (workingMove == null) {
      workingMoveLabel.setText("  Working Move: <none>");
      submitMoveButton.setEnabled(false);
      clearSelectionButton.setEnabled(false);
    } else {
      workingMoveLabel.setText("  Working Move: " + workingMove);
    }
  }
Exemple #4
0
  @Override
  public void stateMachineMetaGame(long timeout)
      throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException {
    if (theCanvas == null) System.err.println("KioskGamer did not receive a canvas.");
    theCanvas.setStateMachine(getStateMachine());

    theGUI = new GameGUI(theCanvas);
    theGUI.setRole(getRole());
    theGUI.setBackground(theGUIPanel.getBackground());
    theGUI.updateGameState(getStateMachine().getInitialState());
    theGUI.addObserver(this);

    theGUIPanel.removeAll();
    theGUIPanel.add("Center", theGUI);
    theGUIPanel.repaint();

    theGUIPanel.setVisible(false);
    theGUIPanel.setVisible(true);
    theGUIPanel.validate();
    theGUIPanel.repaint();
  }
 public void setRole(Role r) {
   theCanvas.setRole(r);
 }
 public void updateGameState(MachineState gameState) {
   moveBeingSubmitted = false;
   theCanvas.updateGameState(gameState);
   updateControls();
 }