public void TestAddingSpells() { SpellBook mySpellBook = new SpellBook(); Spell mySpell = new Teleport("Testing"); mySpellBook.AddSpells(mySpell); Assert.AreEqual(mySpellBook.SpellCount, 1); }
public void TestFetchingSpells() { SpellBook mySpellBook = new SpellBook(); Spell[] arrayofspell; arrayofspell = new Spell[5]; arrayofspell [0] = new Teleport("1. Mitch's mighty mover"); arrayofspell [1] = new Heal("2. Paul's potent poultice"); arrayofspell [2] = new Invisibility("3. David's dashing disapperance"); arrayofspell [3] = new Teleport("4. Stan's stunning shifter"); arrayofspell [4] = new Heal("5. Lachlan's lavish longevity"); foreach (Spell array0to4 in arrayofspell) { mySpellBook.AddSpells(array0to4); } Assert.AreSame(mySpellBook [0], arrayofspell [0]); Assert.AreSame(mySpellBook [1], arrayofspell [1]); Assert.AreSame(mySpellBook [2], arrayofspell [2]); Assert.AreSame(mySpellBook [3], arrayofspell [3]); Assert.AreSame(mySpellBook [4], arrayofspell [4]); }
public static void Main() { Spell.RegisterSpell("Invisibility", typeof(Invisibility)); Spell.RegisterSpell("Heal", typeof(Heal)); Spell.RegisterSpell("Teleport", typeof(Teleport)); SpellBook myspellbook = new SpellBook(); //all available spells in a spellbook SpellBook saveAllCastedSpell = new SpellBook(); //spells that were cast and to save string choice; string Continue; Spell s; string ObjectString; object objects = new object(); //Adding available spells into spellbook myspellbook.AddSpells(new Teleport("1. Mitch's mighty mover <Teleport>")); myspellbook.AddSpells(new Heal("2. Paul's potent poultice <Heal>")); myspellbook.AddSpells(new Invisibility("3. David's dashing disapperance <Invisibility>")); myspellbook.AddSpells(new Teleport("4. Stan's stunning shifter <Teleport>")); myspellbook.AddSpells(new Heal("5. Lachlan's lavish longevity <Heal>")); //to convert list to an array because PrintSpellNamesspellname and PrintSpellNames take in parameter of an array , not list Spell[] spellbook = myspellbook.Spells.ToArray(); ProgramInitialise(spellbook); do { choice = Console.ReadLine(); switch (choice) { case "1": s = myspellbook[0]; Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); Console.WriteLine(s.Cast(objects)); saveAllCastedSpell.AddSpells(s); break; case "2": s = myspellbook[1]; Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); Console.WriteLine(s.Cast(objects)); saveAllCastedSpell.AddSpells(s); break; case "3": s = myspellbook[2]; Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); Console.WriteLine(s.Cast(objects)); saveAllCastedSpell.AddSpells(s); break; case "4": s = myspellbook[3]; Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); Console.WriteLine(s.Cast(objects)); saveAllCastedSpell.AddSpells(s); break; case "5": s = myspellbook[4]; Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); Console.WriteLine(s.Cast(objects)); saveAllCastedSpell.AddSpells(s); break; case "6": Console.WriteLine("Choose between cat and house\n"); ObjectString = Console.ReadLine(); objects = CastOnObject(ObjectString.ToLower()); CastAllSpells(spellbook, objects); foreach (Spell spell in spellbook) { saveAllCastedSpell.AddSpells(spell); } break; case "s": saveAllCastedSpell.Save("Spell.txt"); break; case "c": Console.Clear(); ProgramInitialise(spellbook); break; case "l": try { saveAllCastedSpell.Load("Spell.txt"); } catch (Exception e) { Console.Error.WriteLine("Error loading file:{0}", e.Message); } break; case "q": System.Environment.Exit(1); break; default: Console.WriteLine("Error , please try again"); break; } do { Console.WriteLine("Do you want to continue? Yes or No \n"); Continue = Console.ReadLine(); } while(Continue.ToLower() != "yes" && Continue.ToLower() != "no" && Continue.ToLower() != "y" && Continue.ToLower() != "n"); } while(Continue.ToLower() == "yes" || Continue.ToLower() == "y"); Console.WriteLine("See you again!!"); Console.ReadKey(); }