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 doMyTurn(MessageObject<List<PlayerInfo>> yourTurnMsg) {
    List<PlayerInfo> li = (List<PlayerInfo>) yourTurnMsg.getContent();

    this.playModule.newRound((List<PlayerInfo>) yourTurnMsg.getContent(), this.id);

    Ability chosenAbility = choseRandomAbility();
    AbilityTargetRestriction targetRes = this.choseRandomTarget(chosenAbility);

    ActionObject myAction = new ActionObject(chosenAbility, targetRes);

    //    	////TEST
    //    	IAbilityComponent comp = chosenAbility.getAbilityComponents().getFirst();
    //    	if(comp.getComponentType() == AbilityComponentTypes.SCHADENSABSORBATION){
    //    		Schadensabsorbation sch = (Schadensabsorbation) comp;
    //    		Log.i("GameEngine", "KI sending ... abs:" + String.valueOf(sch.getAbsorbationAmount()));
    //    	}

    //// End
    try {
      Thread.sleep(1500);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      Log.e(TAG, e.getMessage());
    }
    this.connection.sendToHost(MessageFactory.createClientMessage_Action(myAction, id));
  }
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));
  }