コード例 #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);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: symonr9/csharp
        static void damage(Player P, int rdam, int gdam) //Static means that this function is one of a kind, void returns nothing.
        {
            double total = 0;
            double r     = (double)rdam; //type cast int rdam and int gdam into doubles.
            double g     = (double)gdam;

            total += r * (3.8);               //This makes it compatible to be manipulated with decimals/make the total more accurate.
            total += g * (7.2);               //If we don't do this, it will round up and decimals won't be used.
            int t             = (int)total;   //Rounds up total to an int so that we can use it for the Next() function.
            int random_number = R.Next(0, t); //The t becomes the max random number in this round that could be selected.

            Console.WriteLine("{0} took {1} damage!", P.get_name(), random_number);
            P.health_change(random_number);
        }