예제 #1
0
        private static void TurnBasedGame()
        {
            int hero    = 10;
            int monster = 10;

            const int maxAttack             = 10;
            int       turnCounter           = 0;
            RNGCryptoServiceProvider weapon = new RNGCryptoServiceProvider();

            do
            {
                turnCounter++;
                Console.WriteLine($"-*-*-*-*-*-*-*-* turn: {turnCounter} has started *-*-*-*-*-*-*-*-");
                // hero attack to monster
                int attack = weapon.Next(1, maxAttack);
                monster -= attack;
                Console.WriteLine($"Monster was damaged lost {attack} healt and now has {monster}");

                // If the monster is already dead, the game is over.
                // go and check the healts.
                if (monster <= 0)
                {
                    continue;                // break
                }
                // hero attack to monster
                attack = weapon.Next(1, maxAttack);
                hero  -= attack;
                Console.WriteLine($"Hero was damaged lost {attack} healt and now has {hero}");
            } while (hero > 0 && monster > 0);

            Console.WriteLine($"Monster healt {monster}");
            Console.WriteLine($"Hero healt {hero}");
            Console.WriteLine(hero > monster ? "Hero wins!" : "Monster wins!");
        }
예제 #2
0
 public static void Shuffle <T>(this IList <T> list)
 {
     for (var i = 0; i < list.Count; i++)
     {
         list.Swap(i, rng.Next(i, list.Count));
     }
 }
예제 #3
0
 public static IEnumerable <T> Randomise <T>(this IEnumerable <T> source)
 {
     using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
         return(source.OrderBy(i => rng.Next()));
 }
예제 #4
0
 public static IEnumerable <T> Shuffle <T>(this IEnumerable <T> shuffle)
 {
     return(shuffle.OrderBy((a) => RANDOM.Next(int.MaxValue)));
 }