예제 #1
0
        // Method to determine winner of Round.
        // Compares Weapon Types to determine winner.
        // Uses the CanBeat List fields of the Weapon Type to determine if opponent has a weapon that you can beat.
        private string BattleOutcome()
        {
            WeaponsUsed.Add(PlayerOne.CurrentWeapon.WeaponName);
            WeaponsUsed.Add(PlayerTwo.CurrentWeapon.WeaponName);

            var p1Weapon = PlayerOne.CurrentWeapon.GetType();
            var p2Weapon = PlayerTwo.CurrentWeapon.GetType();

            var message = String.Format("\n{0} chose {1}, {2} chose {3}. ",
                                        PlayerOne.Name,
                                        PlayerOne.CurrentWeapon.WeaponName,
                                        PlayerTwo.Name,
                                        PlayerTwo.CurrentWeapon.WeaponName);

            // Determines winner and adds names to Winners List for sorting after the battle
            // Both names are added if a draw.  Only winners name is added for a win.
            if (p1Weapon == p2Weapon)
            {
                Winners.Add(PlayerOne.Name);
                Winners.Add(PlayerTwo.Name);
                return(message + "It's A Draw");
            }
            else if (PlayerOne.CurrentWeapon.CanBeat.Contains(p2Weapon))
            {
                Winners.Add(PlayerOne.Name);
                return(message + PlayerOne.Name + " is the WINNER");
            }
            else
            {
                Winners.Add(PlayerTwo.Name);
                return(message + PlayerTwo.Name + " is the WINNER");
            }
        }
예제 #2
0
        // Iterates through WeaponsUsed List to determine which weapons, and how often they were used
        // in the battle.  Sorts them in descending order and prints the results to the console.
        private void MostUsedWeaponsInBattle()
        {
            Console.WriteLine("\nWeapons used in this battle");
            var result = WeaponsUsed
                         .GroupBy(weaponname => weaponname)
                         .OrderByDescending(weapongroup => weapongroup.Count())
                         .ToList();

            result.ForEach(weapongroup => Console.WriteLine("{0} x {1} used.", weapongroup.Count(), weapongroup.Key));
        }