Exemplo n.º 1
0
        public void CreateBreeds()
        {
            _water = new Breed(null, "Make a pond!", 40);
            _fire  = new Breed(null, "Incineration Blaze!", 30);

            //Lava overrides the only the health
            _lava = new Breed(_fire, null, 45);

            _trollBreed       = new Breed(null, "The troll hits you!", 25);
            _trollArcherBreed = new Breed(_trollBreed, "The troll archer fires an arrow!", 0);
            _trollWizardBreed = new Breed(_trollBreed, "The troll wizard casts a spell on you!", 0);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            /////////////////////////////////////////////////////////////////////
            // two ways of creating & initializing monsters

            // create monster directly using breed - allocation and initialization happens automatically inside constructor
            Breed   troll           = new Breed(null, 10, "Troll attack");
            Monster monsterTrollOne = new Monster(troll, "Troll1");

            // using breed to create monster - separates object allocation and initialization
            Monster monsterTrollTwo = troll.CreateMonster("Troll2");

            Console.WriteLine(string.Format("Troll 1 HP: {0}; Troll 1 attack: {1}",
                                            monsterTrollOne.GetHealth(),
                                            monsterTrollOne.GetAttack()));

            /////////////////////////////////////////////////////////////////////

            Console.WriteLine();

            /////////////////////////////////////////////////////////////////////
            // using inheritance to create base monster breed
            Breed wizardBreed     = new Breed(null, 5, "Generic magic attack");
            Breed fireWizardBreed = new Breed(wizardBreed, 0, "Fire magic attack");
            // passing in 0: inherits from parent
            Breed spellCasterWizardBreed = new Breed(wizardBreed, 8, null);

            Monster m1 = wizardBreed.CreateMonster("M1");
            Monster m2 = fireWizardBreed.CreateMonster("M2");
            Monster m3 = spellCasterWizardBreed.CreateMonster("M3");

            Console.WriteLine(m1.ToString());
            Console.WriteLine(m2.ToString());
            Console.WriteLine(m3.ToString());

            /////////////////////////////////////////////////////////////////////

            /////////////////////////////////////////////////////////////////////
            // created dynamically via json file
            Console.WriteLine("\nCreated via JSON file:");

            ReadJsonData("BreedJson.json");
            foreach (var m in MonstersCreatedViaJSON)
            {
                Console.WriteLine(m.ToString());
            }

            /////////////////////////////////////////////////////////////////////

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            /////////////////////////////////////////////////////////////////////
            // two ways of creating & initializing monsters

            // create monster directly using breed - allocation and initialization happens automatically inside constructor
            Breed troll = new Breed(null, 10, "Troll attack");
            Monster monsterTrollOne = new Monster(troll, "Troll1");

            // using breed to create monster - separates object allocation and initialization
            Monster monsterTrollTwo = troll.CreateMonster("Troll2");

            Console.WriteLine(string.Format("Troll 1 HP: {0}; Troll 1 attack: {1}",
                monsterTrollOne.GetHealth(),
                monsterTrollOne.GetAttack()));

            /////////////////////////////////////////////////////////////////////

            Console.WriteLine();

            /////////////////////////////////////////////////////////////////////
            // using inheritance to create base monster breed
            Breed wizardBreed = new Breed(null, 5, "Generic magic attack");
            Breed fireWizardBreed = new Breed(wizardBreed, 0, "Fire magic attack");
            // passing in 0: inherits from parent
            Breed spellCasterWizardBreed = new Breed(wizardBreed, 8, null);

            Monster m1 = wizardBreed.CreateMonster("M1");
            Monster m2 = fireWizardBreed.CreateMonster("M2");
            Monster m3 = spellCasterWizardBreed.CreateMonster("M3");

            Console.WriteLine(m1.ToString());
            Console.WriteLine(m2.ToString());
            Console.WriteLine(m3.ToString());

            /////////////////////////////////////////////////////////////////////

            /////////////////////////////////////////////////////////////////////
            // created dynamically via json file
            Console.WriteLine("\nCreated via JSON file:");

            ReadJsonData("BreedJson.json");
            foreach (var m in MonstersCreatedViaJSON)
                Console.WriteLine(m.ToString());

            /////////////////////////////////////////////////////////////////////

            Console.ReadLine();
        }
Exemplo n.º 4
0
        private static List <Monster> CreateMonstersFromJsonArray(string jsonString)
        {
            // NOTE: does not work with object reference to parents

            List <Monster> monsterList = new List <Monster>();
            JArray         jArray      = JArray.Parse(jsonString);

            foreach (var a in jArray)
            {
                Breed   b = (Breed)a.ToObject(typeof(Breed));
                Monster m = b.CreateMonster(b.Name);
                monsterList.Add(m);
            }

            return(monsterList);
        }