Exemplo n.º 1
0
        public static void modifyList(IPokedexParser pokedex,
                                      List <MyPokemon> myPokemons,
                                      int pokedexCount,
                                      string fileName)
        {
            string input;
            int    selection = 0;
            int    pageSize  = 10;
            int    pageCount = 0;

            // Get pokemons
            var pageOfPokemons = myPokemons.Take(pageSize);

            do
            {
                Console.WriteLine(string.Format("\t{0,-40}\t{1}", "Name/URL", "Comment"));
                Console.WriteLine(string.Format("\t{0,-40}\t{1}", "--------", "-------"));
                foreach (var pok in pageOfPokemons)
                {
                    Console.WriteLine($"  {pok.Counter+1,3})\t{pok.Name,-40}\t{pok.Comment}");
                    Console.WriteLine($"  \t{pok.Url}");
                }
                Console.WriteLine();
                input = CLI.Prompt($" Enter a number to edit/delete that Pokemon,\n" +
                                   $" 'C' to Continue, or 'M' to return to the Main Menu:  ");

                if (input.ToUpper().Equals("C"))
                {
                    pageCount++;
                    pageOfPokemons = myPokemons.Skip(pageSize * pageCount).Take(pageSize);
                }
                else if (int.TryParse(input, out selection))
                {
                    Console.Write(" Enter your Comment or 'D' to Delete:  ");
                    input = Console.ReadLine();
                    Console.WriteLine("");

                    // Evaluate response:
                    if (input.ToUpper().Equals("D"))
                    {
                        myPokemons.RemoveAt(selection - 1);

                        // Update counters
                        for (var i = 0; i < myPokemons.Count(); i++)
                        {
                            myPokemons[i].Counter = i;
                        }

                        // Get a fresh page of renumbered pokemon
                        pageOfPokemons = myPokemons.Skip(pageSize * pageCount).Take(pageSize);
                    }
                    else
                    {
                        myPokemons[selection - 1].Comment = input;
                    }
                }
            } while (!input.ToUpper().Equals("M") && pageOfPokemons.Count() != 0);

            // Write entire list to file.
            pokedex.WriteToFile(fileName, myPokemons);
        }
Exemplo n.º 2
0
        public static void viewList(List <Pokemon> pokemons,
                                    List <MyPokemon> myPokemons,
                                    ref int pokedexCount,
                                    IPokedexParser pokedex,
                                    string fileName)
        {
            string input;
            int    selection = 0;
            int    pageSize  = 20;
            int    pageCount = 1;

            // Here's where I'll store my list of pokemon to add to my pokedex
            //List<MyPokemon> myPokemons = new List<MyPokemon>();

            var pageOfPokemons = pokemons.Take(pageSize);

            do
            {
                Console.WriteLine(string.Format("\t{0,-25}\t{1}", "Name", "URL"));
                Console.WriteLine(string.Format("\t{0,-25}\t{1}", "----", "---"));
                foreach (var pok in pageOfPokemons)
                {
                    Console.WriteLine($"{pok.Counter+1,3})\t{pok.Name,-25}\t{pok.Url}");
                }
                Console.WriteLine();
                input = CLI.Prompt($" Enter a number to add the Pokemon to your Pokedex,\n" +
                                   $" 'C' to Continue, or 'M' to return to the Main Menu:  ");

                if (input.ToUpper().Equals("C"))
                {
                    pageOfPokemons = pokemons.Skip(pageSize * pageCount).Take(pageSize);
                    pageCount++;
                }
                else if (int.TryParse(input, out selection))
                {
                    // Check for duplicates
                    if (myPokemons.Any(pok => pok.Name == pokemons[selection - 1].Name))
                    {
                        Console.WriteLine(" This Pokemon is already in the Pokedex.  Please select another.");
                        Console.WriteLine(" Press any key to continue.");
                        Console.ReadKey();
                    }
                    else
                    {
                        // Add the selected pokemon to the list
                        MyPokemon pokey = new MyPokemon
                        {
                            Counter = pokedexCount,
                            Name    = pokemons[selection - 1].Name,
                            Url     = pokemons[selection - 1].Url,
                            Comment = ""
                        };
                        myPokemons.Add(pokey);
                        pokedexCount++;
                    }
                }
            } while (!input.ToUpper().Equals("M") && pageOfPokemons.Count() != 0);

            // Write entire list to file.
            pokedex.WriteToFile(fileName, myPokemons);
        }