public void UseSpell(MagicCast spell, Hero targethero) { if (spell != null) { spell.MainCast(targethero); } }
public void UseSpell(MagicCast spell, Hero targethero, uint strength) { if (spell != null) { spell.MainCast(targethero, strength); } }
public void RemoveSpell(MagicCast spell) { if (magicInventory.ContainsKey(spell.ToString())) { magicInventory.Remove(spell.ToString()); } }
public void AddSpell(MagicCast spell) { MagicInventoryObject item = new MagicInventoryObject(spell); if (!magicInventory.ContainsKey(spell.ToString())) { magicInventory.Add(spell.ToString(), item); } }
public MagicCast GetSpell(MagicCast spell) { if (magicInventory.ContainsKey(spell.ToString())) { return((magicInventory[spell.ToString()] as MagicInventoryObject).Spell); } else { return(null); } }
static void Main(string[] args) { //инициализаци персов string name; Hero.Races race = Hero.Races.human; Hero.Gender gender = Hero.Gender.male; int age = 27; Console.WriteLine("Введите имя героя:"); name = Console.ReadLine(); Console.WriteLine("Выберите расу(введите номер расы): 0 - human, 1 - gnome, 2 - elf, 3 - ork, 4 - goblin"); if (Int32.TryParse(Console.ReadLine(), out int r) && r >= 0 && r <= 5) { race = (Hero.Races)r; } Console.WriteLine("Выберите пол(введите номер пола): 0 - male, 1 - female"); if (Int32.TryParse(Console.ReadLine(), out r) && r >= 0 && r <= 1) { gender = (Hero.Gender)r; } Console.WriteLine("Введите возраст"); if (Int32.TryParse(Console.ReadLine(), out r) && r >= 0) { age = r; } MagicHero hero = new MagicHero(name, race, gender, age); MagicHero enemy = new MagicHero("enemy", Hero.Races.ork, Hero.Gender.male, 500); hero.statmnt = Hero.Statements.ill; hero.CurHlth = 50; //добавление инвентаря hero hero.Inventory.AddArtifact(new LifeWaterBottle(LifeWaterBottle.VolumeTypes.small)); hero.Inventory.AddArtifact(new LifeWaterBottle(LifeWaterBottle.VolumeTypes.big)); hero.Inventory.AddArtifact(new DeadWaterBottle(DeadWaterBottle.VolumeTypes.medium)); hero.Inventory.AddArtifact(new LightningStaff(60)); hero.Inventory.AddArtifact(new BasiliskEye()); hero.Inventory.AddArtifact(new PoisonousSaliva(5)); hero.Inventory.AddArtifact(new FrogDecoction()); //добавление спелов hero.magicInventory.AddSpell(new Armor(hero)); hero.magicInventory.AddSpell(new AddHealth(hero)); hero.magicInventory.AddSpell(new Heal(hero)); Draw(hero, enemy); EnemyAtack atack = new EnemyAtack(enemy, hero); Thread enmy = new Thread(new ThreadStart(atack.EnemyAtackThread)); enmy.Start(); while (true) { string s, s2; Console.WriteLine("введите название заклинания или предмета"); s = Console.ReadLine(); Console.WriteLine("введите цель(hero or enemy)"); s2 = Console.ReadLine(); // поиск в инвентаре if (hero.Inventory.FindItem(s)) { if (s2 == "enemy") { Artifact art = hero.Inventory.GetArtifact(s); if (art.HaveStrength) { uint str; Console.WriteLine("введите силу предмета"); UInt32.TryParse(Console.ReadLine(), out str); hero.Inventory.UseArtifact(art, enemy, str); } else { hero.Inventory.UseArtifact(art, enemy); } } else { Artifact art = hero.Inventory.GetArtifact(s); if (art.HaveStrength) { uint str; Console.WriteLine("введите силу предмета"); UInt32.TryParse(Console.ReadLine(), out str); hero.Inventory.UseArtifact(art, hero, str); } else { hero.Inventory.UseArtifact(art, hero); } } } if (hero.magicInventory.FindSpell(s)) { if (s2 == "enemy") { MagicCast spell = hero.magicInventory.GetSpell(s); if (spell.HaveStrength) { uint str; Console.WriteLine("введите силу предмета"); UInt32.TryParse(Console.ReadLine(), out str); hero.magicInventory.UseSpell(spell, enemy, str); } else { hero.magicInventory.UseSpell(spell, enemy); } } else { MagicCast spell = hero.magicInventory.GetSpell(s); if (spell.HaveStrength) { uint str; Console.WriteLine("введите силу предмета"); UInt32.TryParse(Console.ReadLine(), out str); hero.magicInventory.UseSpell(spell, hero, str); } else { hero.magicInventory.UseSpell(spell, hero); } } } Draw(hero, enemy); if (hero.statmnt == Hero.Statements.died) { break; } if (enemy.statmnt == Hero.Statements.died) { Console.Clear(); Console.WriteLine("\n\n\n\n\n\n\n\n#####################################YOU" + " WIN#####################################\n\n\n\n\n\n\n\n"); break; } } enmy.Join(); }
public MagicInventoryObject(MagicCast spell) { Spell = spell; }
public bool FindSpell(MagicCast spell) { return(magicInventory.ContainsKey(spell.ToString())); }