Exemplo n.º 1
0
  @Override
  public void observe(Event event) {
    if (event instanceof MoveSelectedEvent) {
      Move theMove = ((MoveSelectedEvent) event).getMove();
      if (theQueue.size() < 2) {
        theQueue.add(theMove);
      }
    } else if (event instanceof ServerNewGameStateEvent) {
      stateFromServer = ((ServerNewGameStateEvent) event).getState();
    } else if (event instanceof ServerCompletedMatchEvent) {
      theGUI.updateGameState(stateFromServer);

      List<Role> theRoles = getStateMachine().getRoles();
      List<Integer> theGoals = ((ServerCompletedMatchEvent) event).getGoals();

      StringBuilder finalMessage = new StringBuilder();
      finalMessage.append("Goals: ");
      for (int i = 0; i < theRoles.size(); i++) {
        finalMessage.append(theRoles.get(i));
        finalMessage.append(" = ");
        finalMessage.append(theGoals.get(i));
        if (i < theRoles.size() - 1) {
          finalMessage.append(", ");
        }
      }

      theGUI.showFinalMessage(finalMessage.toString());
    }
  }
Exemplo n.º 2
0
 @Override
 public Move stateMachineSelectMove(long timeout)
     throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException {
   theGUI.beginPlay();
   theQueue.clear();
   theGUI.updateGameState(getCurrentState());
   try {
     return theQueue.take();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Exemplo n.º 3
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();
  }