Example #1
0
        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

            // 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";

            using (var writer = XmlWriter.Create(inventoryFile))
                (new XmlSerializer(typeof(Inventory))).Serialize(writer, source);

            using (var rd = new StreamReader(inventoryFile))
            {
                var serializer = new XmlSerializer(typeof(Inventory));
                try
                {
                    Inventory inventory = serializer.Deserialize(rd) as Inventory;
                    if (inventory != null)
                    {
                        foreach (var item in inventory.ItemToQuantity)
                        {
                            Console.WriteLine("Item: {0} Quantity: {1}", item.Key, item.Value);
                        }
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Cannot load {0} due to the following {1}",
                                      inventoryFile, ex.Message);
                }
            }


            Console.ReadKey();
        }
Example #2
0
        public void Init()
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pokemon151.xml");

            PokemonReader reader = new PokemonReader();

            mPokedex = reader.Load(filePath);
        }
Example #3
0
        public void GetHighestAttackPokemonTest()
        {
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            Pokemon pokemon = pokedex.GetHighestAttackPokemon();

            Assert.AreEqual(pokemon.Name, "Mewtwo");
        }
Example #4
0
        public void GetPokemonsofTypeTest()
        {
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            System.Collections.Generic.List <Pokemon> testlist = new System.Collections.Generic.List <Pokemon>();
            testlist = pokedex.GetPokemonsOfType("Grass");

            Assert.AreEqual(testlist.Count, 14);
        }
Example #5
0
        public void GetPokemonBynameTest()
        {
            string        name    = "Bulbasaur";
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            for (int i = 0; i < pokedex.Pokemons.Count; i++)
            {
                if (pokedex.Pokemons[i].Name == name)
                {
                    Assert.AreEqual(pokedex.Pokemons[i].Name, "Bulbasaur");
                }
            }
        }
Example #6
0
        public void GetPokemonByIndexTest()
        {
            int           index   = 1;
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            for (int i = 0; i < pokedex.Pokemons.Count; i++)
            {
                if (pokedex.Pokemons[i].Index == index)
                {
                    Assert.AreEqual(pokedex.Pokemons[i].Index, 1);
                }
            }
        }
Example #7
0
        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.

            Console.ReadKey();
        }
Example #8
0
        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();
        }
Example #9
0
        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();
        }
Example #10
0
        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();
        }