static void Main(string[] args)
        {
            // We create a GameCharater Array (base class) and assign child class objects to it.
            // This is an example of polymorphism.
            var players = new GameCharacter[]
            {
                new Warrior("Utred", 7, 2, "Sword"),
                new Warrior("Ragnar", 5, 4, "Axe"),
                new Wizard("Flora", 2, 7, 8, 1),
                new Wizard("Fauna", 2, 8, 7, 2),
                new Wizard("Merryweather", 2, 8, 7, 3)
            };

            for (int i = 0; i < players.Length; i++)
            {
                // This is the essense of Polymorphism.  We can treat these as their parent (or base) class.
                GameCharacter character = players[i];

                // But that doesn't change what they are... Warriors are always warriors.  So the instantiated type (the child class)
                // is the one thats method is called.
                character.Play();

                // We can access the Move method off of Game Character and it calls the Move method from the instantiated type.
                // even those it is not implemented in the abstract class.
                character.Move(1, 1);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GameCharacter[] gameCharacters = new GameCharacter[5];

            Console.Write("Enter player name: ");
            var name = Console.ReadLine();

            Console.Write("Enter strength from 1-10: ");
            var strength = int.TryParse(Console.ReadLine(), out var resultstrength) ? resultstrength : default;

            Console.Write("Enter intelligence from 1-10: ");
            var intel = int.TryParse(Console.ReadLine(), out var resultintel) ? resultintel : default;


            gameCharacters[0] = new Wizard(intel, strength, name, 7, 7);
            gameCharacters[1] = new Wizard(intel, strength, name, 8, 2);
            gameCharacters[2] = new Wizard(intel, strength, name, 3, 7);
            gameCharacters[3] = new Warrior(intel, strength, name, "bow and arrow");
            gameCharacters[4] = new Warrior(intel, strength, name, "true love");



            foreach (var character in gameCharacters)
            {
                Console.WriteLine(character.Play());
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            GameCharacter[] gameCharacters = new GameCharacter[5];
            gameCharacters[0] = new Warrior("Aria", 50, 80, "Needle");
            gameCharacters[1] = new Warrior("Daenerys", 65, 75, "dragon");
            gameCharacters[2] = new Wizard("Merlin", 20, 90, 75, 55);
            gameCharacters[3] = new Wizard("Harry", 30, 80, 95, 22);
            gameCharacters[4] = new Wizard("Simon", 18, 100, 88, 60);

            for (int i = 0; i < gameCharacters.Length; i++)
            {
                gameCharacters[i].Play();
                Console.WriteLine();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            GameCharacter gameCharacter = new GameCharacter("John", 98, 75);

            gameCharacter.Play();


            GameCharacter[] gameCharacters;
            gameCharacters    = new GameCharacter[5];
            gameCharacters[0] = new SubclassWarrior("Dave", 100, 60, "sword");
            gameCharacters[1] = new SubclassWarrior("Paul", 100, 60, "broad sword");
            gameCharacters[2] = new SubclassWizard("Steven", 60, 100, 80, 75);
            gameCharacters[3] = new SubclassWizard("Chris", 60, 100, 80, 75);
            gameCharacters[4] = new SubclassWizard("Ollie", 60, 100, 80, 75);

            for (int i = 0; i < gameCharacters.Length; i++)
            {
                gameCharacters[i].Play();
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            string[] gameCharacters = new string[5];

            GameCharacter       myGameCharacter       = new GameCharacter();
            Warrior             myWarrior             = new Warrior();
            MagicUsingCharacter myMagicUsingCharacter = new MagicUsingCharacter();
            Wizard myWizard = new Wizard();


            Console.Write("Enter the character name ");
            var Name = Console.ReadLine();

            Console.Write("Enter the character strength: ");
            var Strength = int.Parse(Console.ReadLine()),

                Console.Write("Enter the character intelligence: ");
            var Intelligence = int.Parse(Console.ReadLine());


            foreach (var GameCharacter in gameCharacters)
            {
                for (int i = 0; i < 3; i++)
                {
                    myWizard.Play();
                }
                for (int i = 3; i > 2; i++)
                {
                    myWarrior.Play();
                }
                break;
            }

            /* myGameCharacter.Play();
             * myWarrior.Play();
             * myMagicUsingCharacter.Play();
             * myWizard.Play(); */
        }