예제 #1
0
파일: Program.cs 프로젝트: symonr9/csharp
        public static Random R = new Random(); //Random number generator
        static void battle(Player p1, Rat [] r, Goblin [] g)
        {
            bool win = false;

            Console.WriteLine("You have entered the dungeon and there are {0} Rat(s) and {1} Goblin(s)!", r.Length, g.Length);
            while (win == false)                                          //run everything within this loop while win is false or if we hit a break statement.
            {
                if (p1.get_health() <= 0)                                 //if statement performs if condition is true
                {
                    Console.WriteLine("Oh no! {0} died!", p1.get_name()); //Writing various things onto the console
                    Console.ReadKey();
                    Console.WriteLine("Game Over!!!");
                    Console.ReadKey();
                    break;
                }
                else if (r.Length == 0 && g.Length == 0) //checks this condition if first if statement if false
                {
                    Console.WriteLine("You have defeated all of the Rats and Goblins!");
                    Console.ReadKey(); //ReadKey() is used to pause the screen.
                    Console.WriteLine("Yayyyy!!!");
                    Console.ReadKey();
                    win = true;
                }
                else //if both if statements above are false, this set of statements run
                {
                    attack(p1, r, g);
                    Console.WriteLine("{0} health is: {1}", p1.get_name(), p1.get_health());
                    Console.ReadKey();
                    damage(p1, r.Length, g.Length); //Call the damage function
                    Console.WriteLine("There are currently {0} rats and {1} goblins...", r.Length, g.Length);
                }
            }
        }