public void Init() { mFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pokemonBag.xml"); string fileLoad = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pokemon151.xml"); mPokemonBag = new PokemonBag(); mPokedex = new PokemonReader().Load(fileLoad); }
public void PokemonBag_Load() { if (File.Exists(mFilePath)) { PokemonBag temp = mPokemonBag.Load(mFilePath); temp.Pokemons.ForEach(Item => Console.WriteLine(Item)); Assert.IsTrue(temp.Pokemons.Count >= 5); } }
static void Main(string[] args) { Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition"); PokemonReader reader = new PokemonReader(); PokemonSaver saver = new PokemonSaver(); Pokedex pokedex = reader.Load_Pokedex("pokemon151.xml"); // List out all the pokemons loaded foreach (Pokemon pokemon in pokedex.Pokemons) { Console.WriteLine(pokemon.Name); } PokemonBag theBag = new PokemonBag(); theBag.AddPokemon(pokedex, "bulbasaur"); theBag.AddPokemon(pokedex, "bulbasaur"); theBag.AddPokemon(pokedex, "charizard"); theBag.AddPokemon(pokedex, "mew"); theBag.AddPokemon(pokedex, "dragonite"); string fileName = "myPokemonBag.xml"; // Serializting and saving pokemonBeg object with exception handling try { saver.Save_PokeBag(theBag, fileName); } catch (Exception e) { Console.WriteLine(string.Format("\nSaving {0} failed, due to error: {1}\n", fileName, e.Message)); } // Deserializting and loading pokemonBag object with exception handling PokemonBag newBag = new PokemonBag(); try { newBag = reader.Load_PokemonBag(fileName); } catch (Exception e) { Console.WriteLine(string.Format("Loading {0} failed, due to error: {1}", fileName, e.Message)); } //TODO::add a beg pretty print function in pokemonbag class. ----DONE newBag.PrettyPrint(pokedex); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition"); PokemonReader reader = new PokemonReader(); Pokedex pokedex = reader.LoadPokedex("pokemon151.xml"); // List out all the pokemons loaded foreach (Pokemon pokemon in pokedex.Pokemons) { //Console.WriteLine(pokemon.Name); } // TODO: Add a pokemon bag with 2 bulbsaur, 1 charizard, 1 mew and 1 dragonite // and save it out and load it back and list it out. PokemonBag pokemonbag = new PokemonBag(); pokemonbag.Pokemons.Add(1); pokemonbag.Pokemons.Add(1); pokemonbag.Pokemons.Add(6); pokemonbag.Pokemons.Add(151); pokemonbag.Pokemons.Add(149); Pokedex newPokedex = new Pokedex(); using (PokemonUtil pokemonUtil = new PokemonUtil("PokemonBag")) { pokemonUtil.Init(); pokemonUtil.AddPokemonsToProcess(ref pokemonbag, ref pokedex); newPokedex.Pokemons.AddRange(pokemonUtil.PokemonsToProcess); pokemonUtil.Write(); pokemonUtil.Print(); pokemonUtil.Clear(); } PokemonWriter pokemonWriter = new PokemonWriter(); pokemonWriter.SavePokemons("PokemonBag.xml", ref newPokedex); Pokedex dex = reader.LoadPokedex("PokemonBag.xml"); // TODO: load the pokemon151 xml XElement pokemon151XML = XElement.Load(@"pokemon151.xml"); // Console.WriteLine(pokemon151XML); // TODO: Add item reader and print out all the items Item itemdata = new Item(); List <Item> itemlist = new List <Item>(); XmlTextReader readerItem = new XmlTextReader("itemData.xml"); while (readerItem.Read()) { if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Name") { string name = readerItem.ReadElementContentAsString(); itemdata.Name = name; // Console.WriteLine("Name: " + itemdata.Name); } if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "UnlockRequirement") { string UnlockRequirement = readerItem.ReadElementContentAsString(); itemdata.UnlockRequirement = Int32.Parse(UnlockRequirement); // Console.WriteLine("UnlockRequirement: " + itemdata.UnlockRequirement); } if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Description") { string Description = readerItem.ReadElementContentAsString(); itemdata.Description = Description; // Console.WriteLine("Description: " + itemdata.Description); } if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Effect") { string Effect = readerItem.ReadElementContentAsString(); itemdata.Effect = Effect; //Console.WriteLine("Effect: " + itemdata.Effect); itemlist.Add(itemdata); itemdata = new Item(); } } foreach (Item i in itemlist) { i.Print(); } // TODO: hook up item data to display with the inventory Inventory source = new Inventory() { ItemToQuantity = new Dictionary <object, object> { { "Poke ball", 10 }, { "Potion", 10 } } }; // TODO: move this into a inventory with a serialize and deserialize function. source.Serialize(source, "inventory.xml"); source.Deserialize("inventory.xml"); Console.ReadKey(); }
static void Main(string[] args) { ItemsData data = new ItemsData(); Item testitem = new Item(); Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition"); PokemonReader reader = new PokemonReader(); Pokedex pokedex = reader.Load("pokemon151.xml"); // List out all the pokemons loaded foreach (Pokemon pokemon in pokedex.Pokemons) { Console.WriteLine(pokemon.Name); } // TODO: load the pokemon151 xml XmlDocument loadPokemon151 = new XmlDocument(); loadPokemon151.Load("pokemon151.xml"); // TODO: Add item reader and print out all the items using (XmlReader itemReader = XmlReader.Create("itemData.xml")) { while (itemReader.Read()) { if (itemReader.IsStartElement()) { switch (itemReader.Name.ToString()) { case "Name": Console.WriteLine("Item Name : " + itemReader.ReadElementContentAsString()); break; case "UnlockRequirement": Console.WriteLine("UnlockRequirement : " + itemReader.ReadElementContentAsFloat()); break; case "Description": Console.WriteLine("Description : " + itemReader.ReadElementContentAsString()); break; case "Effect": Console.WriteLine("Effect : " + itemReader.ReadElementContentAsString()); break; } data.Items.Add(testitem); } Console.WriteLine(""); } } // TODO: hook up item data to display with the inventory var source = new Inventory() { ItemToQuantity = new Dictionary <object, object> { { "Poke ball", 10 }, { "Potion", 10 } } }; // TODO: move this into a inventory with a serialize and deserialize function. source.Serialize(source); source.Deserialize("inventory.xml"); PokemonBag mybag = new PokemonBag(); mybag.Pokemons.Add(1); mybag.Pokemons.Add(1); mybag.Pokemons.Add(6); mybag.Pokemons.Add(151); mybag.Pokemons.Add(149); FileStream fs = new FileStream(@"serializePokemon.dat", FileMode.Create);//path of file BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, mybag); fs.Close(); fs = new FileStream(@"serializePokemon.dat", FileMode.Open); BinaryFormatter nbf = new BinaryFormatter(); PokemonBag mylist = nbf.Deserialize(fs) as PokemonBag; Console.WriteLine("\nList of the the pokemons caught"); foreach (int i in mylist.Pokemons) { Console.WriteLine(pokedex.GetPokemonByIndex(i).Name); } Console.WriteLine(pokedex.GetHighestHPPokemon().Name); Console.WriteLine(pokedex.GetHighestAttackPokemon().Name); Console.WriteLine(pokedex.GetHighestDefensePokemon().Name); Console.WriteLine(pokedex.GetHighestMaxCPPokemon().Name); // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite // and save it out and load it back and list it out. Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition"); PokemonReader reader = new PokemonReader(); Pokedex pokedex = reader.Load("pokemon151.xml"); // List out all the pokemons loaded foreach (Pokemon pokemon in pokedex.Pokemons) { Console.WriteLine(pokemon.Name); } // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite // and save it out and load it back and list it out. // TODO: Add item reader and print out all the items ItemReader itemReader = new ItemReader(); ItemsData itemsData = itemReader.Load("itemData.xml"); foreach (var item in itemsData.Items) { Console.WriteLine(item.Name); } // TODO: hook up item data to display with the inventory var source = new Inventory() { ItemToQuantity = new Dictionary <object, object> { { "Poke ball", 10 }, { "Potion", 10 } } }; // TODO: move this into a inventory with a serialize and deserialize function. string inventoryFile = "inventory.xml"; source.Load(inventoryFile, itemsData); source.Save("invent.xml"); Console.WriteLine("=========Bag========="); PokemonBag pokebag = new PokemonBag(); pokebag.Pokemons.Add(pokedex.GetPokemonByName("Bulbasaur")); pokebag.Pokemons.Add(pokedex.GetPokemonByName("Bulbasaur")); pokebag.Pokemons.Add(pokedex.GetPokemonByName("Charizard")); pokebag.Pokemons.Add(pokedex.GetPokemonByName("Mew")); pokebag.Pokemons.Add(pokedex.GetPokemonByName("Dragonite")); Pokedex bagdex = new Pokedex(); bagdex.Pokemons = pokebag.Pokemons; reader.Save("bagdex", bagdex); Pokedex loadDex = reader.Load("bagdex.xml"); foreach (Pokemon pokemon in loadDex.Pokemons) { Console.WriteLine(pokemon.Name); } Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition"); PokemonReader reader = new PokemonReader(); Pokedex pokedex = reader.Load("pokemon151.xml"); Console.WriteLine("Displaying List of Pokemon:"); // List out all the pokemons loaded foreach (Pokemon pokemon in pokedex.Pokemons) { Console.WriteLine(pokemon.Name); } ItemReader itemReader = new ItemReader(); ItemsData itemsDatafile = itemReader.Load("itemData.xml"); Console.WriteLine("\nDisplaying List of Items from file"); foreach (Item item in itemsDatafile.Items) { item.Print(); } int iLevelLock = 10; Console.WriteLine("Displaying items unlocked at level {0}", iLevelLock); List <Item> UnlockedItems = itemsDatafile.UnlockedItemsAtLevel(iLevelLock); foreach (Item item in UnlockedItems) { item.Print(); } string itemname = "Super Potion"; Console.WriteLine("Searching for item {0}", itemname); itemsDatafile.FindItem(itemname).Print(); string InventoryFile = "inventory.xml"; Console.WriteLine("-----Creating Inventory-----"); var source = new Inventory() { ItemToQuantity = new Dictionary <object, object> { { "Poke ball", 10 }, { "Potion", 10 }, { "Premier ball", 20 }, { "Revive", 3 }, { "Great ball", 8 }, { "Hyper Potion", 2 } } }; source.Serialize(source); source.Deserialize(InventoryFile); string entry = "Poke ball"; Console.WriteLine("\nSearching for {0} in Inventory", entry); source.FindItem("Poke ball"); Console.WriteLine("\nDisplaying items in inventory whose Level Req < {0}", iLevelLock); source.UnlockItems(iLevelLock, itemsDatafile); // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite // and save it out and load it back and list it out. Console.WriteLine("\nSaving more pokemons inside bag\n"); PokemonBag bag = new PokemonBag(); bag.Add(pokedex.GetPokemonByName("Bulbasaur").Index); bag.Add(pokedex.GetPokemonByName("Bulbasaur").Index); bag.Add(pokedex.GetPokemonByName("Charizard").Index); bag.Add(pokedex.GetPokemonByName("Mew").Index); bag.Add(pokedex.GetPokemonByName("Dragonite").Index); const string filepath = "PokeBag.xml"; bag.Save(filepath); PokemonBag loadResult = bag.Load(filepath); Console.WriteLine("\nLoad all pokemons from bag..\n"); loadResult.Pokemons.ForEach(item => Console.WriteLine(item)); Console.ReadKey(); }