Ejemplo n.º 1
0
 @Override
 public void observe(Event event) {
   if (event instanceof MoveSelectedEvent) {
     workingMove = ((MoveSelectedEvent) event).getMove();
     if (((MoveSelectedEvent) event).isFinal()) {
       moveBeingSubmitted = true;
       updateControls();
       notifyObservers(new MoveSelectedEvent(workingMove));
     }
     updateControls();
   }
 }
Ejemplo n.º 2
0
  public void showFinalMessage(String theMessage) {
    workingMoveLabel.setText(theMessage);
    workingMoveLabel.setForeground(Color.RED);
    gameOver = true;
    updateControls();

    validate();
    repaint();
  }
Ejemplo n.º 3
0
  @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));
      }
    }
  }
Ejemplo n.º 4
0
  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();
  }
Ejemplo n.º 5
0
 public void updateGameState(MachineState gameState) {
   moveBeingSubmitted = false;
   theCanvas.updateGameState(gameState);
   updateControls();
 }
Ejemplo n.º 6
0
 public void beginPlay() {
   stillMetagaming = false;
   updateControls();
 }