示例#1
0
        // Initial menu functions
        public static void Run()
        {
            int input = 0;

            do
            {
                try
                {
                    input = Display();

                    switch (input)
                    {
                    case 1:
                        input = -1;
                        var pokedex = new Pokedex();
                        PokedexMenu.Run();
                        break;

                    case 2:
                        input = -1;
                        TeamMenu.Run();
                        break;

                    case -1:
                        Console.Clear();
                        Console.WriteLine("See ya later... gotta catch 'em all!");
                        break;

                    default:
                        Console.WriteLine("Invalid choice");
                        System.Threading.Thread.Sleep(1000);
                        Console.Clear();
                        Run();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine();
                    Console.WriteLine(" ERROR: " + e);
                }
            }while (input != -1);
        }
示例#2
0
        // Gets and loads the team from the csv file
        public Team LoadTeam()
        {
            // Load from user's system folder
            // Only one team can be saved and loaded... for now!
            string path     = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var    filePath = Path.Combine(path, $"myPokemonTeam.csv");

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        var            teamData    = line.Trim().Split(',');
                        string         teamName    = teamData[0];
                        List <Pokemon> teamPokemon = new List <Pokemon>();
                        var            subPokemon  = teamData.Skip(1);

                        foreach (string x in subPokemon)
                        {
                            if (!string.IsNullOrEmpty(x))
                            {
                                Pokedex pokedex     = new Pokedex();
                                Pokemon thisPokemon = pokedex.GetPokemonByName(x);
                                teamPokemon.Add(thisPokemon);
                            }
                        }
                        Name    = teamName;
                        Pokemon = teamPokemon;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Pokemon team file not found. Try making a new team and saving!");
            }
            return(this);
        }
示例#3
0
        public static void Run()
        {
            int     input   = 0;
            Pokedex pokedex = new Pokedex();

            do
            {
                try
                {
                    input = Display();

                    switch (input)
                    {
                    case 1:
                        input = 4;
                        pokedex.GetPokedex();
                        System.Threading.Thread.Sleep(1000);
                        break;

                    case 2:
                        // Ask for name, return pokemon entry
                        Console.Write("Enter name: ");
                        try
                        {
                            string  pokemonSearch = Console.ReadLine();
                            Pokemon result        = pokedex.GetPokemonByName(pokemonSearch);
                            result.PokedexEntry();
                            Console.Write("Press Enter to go back...");
                            Console.ReadLine();
                            Console.Clear();
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("Please enter a valid Pokemon name.");
                            System.Threading.Thread.Sleep(2000);
                        }
                        break;

                    case 3:
                        // Display a Pokemon type listing, choose, display entires of pokemon
                        Console.WriteLine("Choose from one of these types: ");
                        pokedex.ShowTypeListing();
                        Console.Write("Enter Pokemon type: ");
                        try
                        {
                            string typeSearch = Console.ReadLine();
                            var    typeResult = pokedex.GetPokemonByType(typeSearch);
                            foreach (Pokemon pkmn in typeResult)
                            {
                                Console.WriteLine(pkmn);
                            }
                            Console.Write("Press Enter to go back...");
                            Console.ReadLine();
                            Console.Clear();
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("Enter a valid Pokemon type.");
                            System.Threading.Thread.Sleep(2000);
                        }
                        break;

                    case 4:
                        Console.Clear();
                        Menu.Run();
                        break;

                    default:
                        Console.WriteLine("Invalid choice");
                        System.Threading.Thread.Sleep(1000);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine();
                    Console.WriteLine(" ERROR: " + e);
                }
            }while (input != 4);
        }