コード例 #1
0
        public void Battle(Hokemon Attacker, Hokemon Defender) // Passing in two PARAMETERS
                                                               // two Hokemon for the Battle
        {
            Hokemon tempHoke;
            int     round = 0;

            while (Convert.ToInt32(Attacker.Health) >= 0 || Convert.ToInt32(Defender.Health) >= 0)
            {
                int attackValue  = Attacker.attackCalculator();
                int defenceValue = Defender.defenceCalculator();

                round += 1; // Alternate to statement round = round + 1

                Console.WriteLine("\n******** ROUND {0} ********\n", round);

                for (int i = 0; i < 2; i++)
                {
                    // Attacker attacks

                    Console.WriteLine("{0}: Attacks with value {1} ", Attacker.Name, attackValue);

                    // Defenders defence

                    Console.WriteLine("{0}: Defends with Value {1}", Defender.Name, defenceValue);

                    Console.WriteLine("{0}: health = {1}", Defender.Name, Defender.Health);

                    // Calculate the impact of the Attach on defenders health

                    Defender.Health = (Defender.Health + defenceValue) - attackValue;

                    Console.WriteLine("{0}: New health value = {1} // Calc: {1} + {2} - {3}", Defender.Name, Defender.Health, defenceValue, attackValue);

                    // IMPORTANT part of the Battle
                    Console.WriteLine("\n\n*** SWITCHING TURNS - Attacker now the Defender ***\n");

                    tempHoke = Attacker; // tempHoke is assigned the attacker object
                    Attacker = Defender;
                    Defender = tempHoke;
                }
            }

            if (Attacker.Health > Defender.Health)
            {
                Console.WriteLine("{0} WINS", Attacker.Name);
            }
            else
            {
                Console.WriteLine("{0} WINS", Defender.Name);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the world of Hokemon!\n\n");

            Hokemon HokeObject01 = new Hokemon(); // INSTANTIATING our first object

            HokeObject01.get_details();

            System.Threading.Thread.Sleep(1000); // Sleep for 1 second

            // Create a second Hokemon
            Hokemon Hoke02 = new Hokemon();

            Hoke02.get_details();

            HokeObject01.about();
            Hoke02.about();

            /*
             * Halor halorHoke01 = new Halor();
             * halorHoke01.get_details();
             *
             * // Example of POLYMORPHISM with the about method in following objects
             * Hoke02.about();
             * halorHoke01.about();
             */

            Battle_Arena firstArena = new Battle_Arena(); // Instiating the object firstArena

            // from the Battle_Arena CLASS


            firstArena.RequestAChallenger(HokeObject01); // ARGUMENT HokeObject01
                                                         // passed into the
                                                         // firstArena object
                                                         // method Req....
            firstArena.AcceptingTheBattle(HokeObject01, Hoke02);

            firstArena.Battle(HokeObject01, Hoke02); // Starts the Battle
        }
コード例 #3
0
 public void Accept_Battle(Hokemon contendor01, Hokemon contendor02)
 {
     Console.WriteLine("{0}: 'I accept the challenge to fight you, {1}' ", contendor02.Name, contendor01.Name);
     System.Threading.Thread.Sleep(1000);
     Console.WriteLine("{1}: 'Great {0}, Let's BATTLE!' ", contendor02.Name, contendor01.Name);
 }
コード例 #4
0
 public void Request_Challenger(Hokemon contendor)
 {
     Console.WriteLine("{0}: say's 'I want a BATTLE... Who is ready to challenge me?'", contendor.Name);
 }
コード例 #5
0
 public void AcceptingTheBattle(Hokemon contender01, Hokemon contendor02)
 {
     Console.WriteLine("{0}: 'I accept the challenge to fight {1}' ", contendor02.Name, contender01.Name);
     System.Threading.Thread.Sleep(2000);
     Console.WriteLine("{1}: 'Great {0}, lets start a BATTLE!!!' ", contendor02.Name, contender01.Name);
 }