Пример #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
            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();
        }
Пример #2
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();
        }