public void CheckHealth() { Debug.Log("Fire elemental health: " + _fireElemental.GetHealth()); Debug.Log("Water elemental health: " + _waterElemental.GetHealth()); Debug.Log("Lava elemental health: " + _lavaElemental.GetHealth()); Debug.Log("Troll health: " + _troll.GetHealth()); Debug.Log("Troll Archer health: " + _trollArcher.GetHealth()); Debug.Log("Troll Wizard health: " + _trollWizard.GetHealth()); }
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(); }
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(); }