コード例 #1
0
ファイル: War.java プロジェクト: DRaines234/WarCardGame
  public static void main(String[] args) {
    WarGame game;
    int games = 100000;
    int numTurns = 0;
    int avgNumTurns = 0;
    int maxTurns = 0;
    int minTurns = games;
    int currentTurns;
    for (int i = 0; i <= games; i++) {
      currentTurns = 0;
      game = new WarGame();
      while (!game.isGameOver()) {
        game.PlayRound();
        numTurns++;
        currentTurns++;
        // System.out.println(numRounds);
      }
      if (currentTurns > maxTurns) {
        maxTurns = currentTurns;
      } else if (currentTurns < minTurns) {
        minTurns = currentTurns;
      }
    }
    avgNumTurns = numTurns / games;

    System.out.println("Average Number of turns per game is " + avgNumTurns);
    System.out.println("The max number of turns in a game out of " + games + " is " + maxTurns);
    System.out.println("The minimum number of turns in a game out of " + games + " is " + minTurns);
  }
コード例 #2
0
 public boolean handleDeath(WarPlayer player, String deathMessage) {
   WarGame game = warzone.getGame().orElseThrow(IllegalStateException::new);
   plugin.delayTask(
       3,
       () -> {
         if (player.isPlayingWar()) game.resetPlayerState(player);
       });
   return true;
 }
コード例 #3
0
 public boolean handleDamage(WarPlayer defender, double damage, WarDamageCause cause) {
   WarGame game = warzone.getGame().orElseThrow(IllegalStateException::new);
   if (cause instanceof WarDamageCause.Combat) {
     WarPlayer attacker = ((WarDamageCause.Combat) cause).getAttacker();
     if (game.getPlayerTeam(defender) == game.getPlayerTeam(attacker)) {
       attacker.sendMessage("Do not target your own team!");
       return true;
     }
     game.addAttack(attacker, defender);
   }
   // prevent skeletons from shooting players in zones
   if (cause instanceof WarDamageCause.Creature) {
     return true;
   }
   // player would die by this blow
   if (defender.getHealth() - damage < 1) {
     // send the death message for the most recent damage cause
     game.broadcast(cause.getDeathMessage());
     // find a recent attack from a player
     Optional<WarGame.Attack> first =
         game.getAttacks()
             .stream()
             .filter(a -> a.getDefender() == defender)
             .filter(a -> System.currentTimeMillis() - a.getTime() < LAST_ATTACK_DELAY_MS)
             .findFirst();
     if (first.isPresent()) {
       WarGame.Team beneficiary = game.getPlayerTeam(first.get().getAttacker());
       beneficiary.addPoints(1);
       game.broadcast(MessageFormat.format("Team {0} gains 1 point.", beneficiary.getName()));
     }
     game.checkForEndRound();
     game.resetPlayerState(defender);
     game.resetPlayerState(defender);
     return true;
   }
   return false;
 }