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 Ability choseRandomAbility() {
    int maxAbil =
        playModule.getAbilityChooser().getAllAbilitys().keySet().size() - 1; // da von 0 an gezhlt
    int random = this.myRandomWithHigh(0, maxAbil);

    return this.playModule.getAbilityChooser().getAbility(random);
  }
Beispiel #3
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));
  }