Beispiel #1
0
  @SuppressWarnings("unchecked")
  public void playTheGame() {
    boolean gameIsNotOver = true;
    while (gameIsNotOver) {
      MessageObject<?> msgFromHost = this.connection.listenToBroadcast();

      switch (msgFromHost.messageType) {
        case ABILITY_COMPONENT:
          doDealWith(msgFromHost);
          break;
        case GAME_OVER:
          gameIsNotOver = false;
          this.connection.closeConnection();
          break;
        case GAME_START:
          this.id = (Integer) msgFromHost.getContent();
          PlayerInfo info = new PlayerInfo(kiName, id);
          info.setCurrentLife(playModule.getMonster().getCurrentLifePoints());
          info.setMaxLife(playModule.getMonster().getMaxLifePoints());
          this.connection.sendToHost(MessageFactory.createClientMessage_GameStart(info, id));
          break;
        case YOUR_TURN:
          doMyTurn((MessageObject<List<PlayerInfo>>) msgFromHost);
          break;
        default:
          break;
      }
    }
  }
Beispiel #2
0
  private void doDealWith(MessageObject<?> dealWithMsg) {
    /// CHRIS test
    AbilityComponentDirector director = playModule.getMonstersAbilityComponentDirector();
    AbilityComponentList abilityComponents = (AbilityComponentList) dealWithMsg.getContent();
    PlayerInfo info = new PlayerInfo(kiName, id);
    AnswerObject answerObject = director.handleAbilityComponents(abilityComponents, info);

    if (this.playModule.getMonster().getCurrentLifePoints() <= 0) {
      answerObject.setMonsterIsDead(true);
    }

    connection.sendToHost(MessageFactory.createClientMessage_Answer(answerObject, id));
  }