예제 #1
0
 /// <summary>
 /// Count all the Ranks
 /// </summary>
 private void CountRanks()
 {
     GeneralCount     = Recruits.Count(s => s.Rank == Rank.General);
     CaptainCount     = Recruits.Count(s => s.Rank == Rank.Captain);
     SergeantCount    = Recruits.Count(s => s.Rank == Rank.Sergeant);
     PrivateCount     = Recruits.Count(s => s.Rank == Rank.Private);
     MaxSergeantCount = PrivateCount / PrivatesNeededPerSergeant;
 }
예제 #2
0
        /// <summary>
        /// Battle against an enemy. The Army will Attack first and Defend Second.
        /// </summary>
        /// <param name="enemy"></param>
        public void Battle(IEnemy enemy)
        {
            while (true)
            {
                if (!ReadyForBattle())
                {
                    continue;
                }

                DisplayBeginBattleMessage(enemy);

                while (!(enemy.IsDead || IsDefeated))
                {
                    Attack(enemy);

                    if (enemy.IsDead)
                    {
                        break;
                    }

                    Defend(enemy);

                    var soldierCount = Recruits.Count(r => !r.IsDead);

                    if (soldierCount <= 0)
                    {
                        break;
                    }

                    var soldierCasualties = Recruits.Count(r => r.IsDead);
                    var battleReport      = BuildBattleReport(soldierCasualties, soldierCount, enemy.HitPoints);
                    _writer.WriteMessage(battleReport);

                    UserInputForNextRound();
                }

                if (enemy.IsDead)
                {
                    ArmyVictoriousMessage(enemy);
                }
                else
                {
                    ArmyDefeatedMessage(enemy);
                }

                break;
            }
        }