예제 #1
0
  /**
   * Random roll chooses which army will execute it's action first, sets those actions and then
   * executes them turn for turn. Also rolls for a chance that random event will occur.
   */
  public void engageArmies() {
    while (!firstArmy.isDefeated() && !secondArmy.isDefeated()) {
      turns++;
      System.out.println("\nTURN " + turns);

      if (RandomEventGenerator.eventHappens()) {
        executeRandomEvent();
      }

      System.out.println(firstArmy.getDetails());
      System.out.println(secondArmy.getDetails());

      if (firstStrikeChance() > firstStrikeChance()) {
        System.out.println("You have first strike!");
        setPlayerAction();
        setComputerAction();
        executeFight(firstArmy, secondArmy);
      } else {
        System.out.println("Your opponent has first strike!");
        setPlayerAction();
        setComputerAction();
        executeFight(secondArmy, firstArmy);
      }
    }
  }
예제 #2
0
  /**
   * After setting which army will execute it's action first it will execute morale modifiers
   * accordingly, execute action of the army with first strike and then check if the other army has
   * been defeated. If it has the game is over and defeat is called out. Otherwise it will execute
   * the action of the other army and check if the first army has been defeated. If it has the game
   * is over and defeat is called out.
   *
   * @param firstStrikeArmy
   * @param secondStrikeArmy
   */
  private void executeFight(Army firstStrikeArmy, Army secondStrikeArmy) {
    firstStrikeArmy.increaseMorale(0.05f);
    secondStrikeArmy.reduceMorale(0.05f);

    if (firstStrikeArmy.getAction() == 1) {
      secondStrikeArmy.takeDamage(firstStrikeArmy.dealDamage(maxTurnDamage));
    } else if (firstStrikeArmy.getAction() == 2) {
      firstStrikeArmy.executeSpecial();
    }

    if (secondStrikeArmy.isDefeated()) {
      callOutDefeat(secondStrikeArmy.getName());
    } else {
      if (secondStrikeArmy.getAction() == 1) {
        firstStrikeArmy.takeDamage(secondStrikeArmy.dealDamage(maxTurnDamage));
      } else if (secondStrikeArmy.getAction() == 2) {
        secondStrikeArmy.executeSpecial();
      }

      if (firstStrikeArmy.isDefeated()) {
        callOutDefeat(firstStrikeArmy.getName());
      }
    }
  }