コード例 #1
0
        static void UserApp()
        {
            Console.WriteLine("Welcome to pokemon team maker");
            Console.WriteLine("Searching for teams created by you...");
            List <Pokemon> myPokemon = new List <Pokemon>();
            Pokedex        myDex     = new Pokedex();

            // search if any teams have been created by the user.
            // this is down to how the team is stored.

            string[] team = GetTeam(username);

            //needs t have
            #region -this is for if a team is present-
            foreach (Pokemon p in myDex.pokemonList)
            {
                foreach (var item in team)
                {
                    if (item == "" || item == null)
                    {
                        break;
                    }
                    if (p.DexNumber == Convert.ToInt32(item))
                    {
                        myPokemon.Add(p);
                    }
                }
            }

            Console.WriteLine("Your current team is:");
            foreach (var item in myPokemon)
            {
                Console.WriteLine("|{0}|{1}|", item.DexNumber, item.Name);
            }
            #endregion
            Console.WriteLine("please enter one of the following options:");
            Console.WriteLine("1 for change team");
            Console.WriteLine("2 for replace a pokemon");
            Console.WriteLine("3 to save and exit");
            Console.WriteLine("4 to print team.");
            Console.WriteLine("EXIT to exit without saving");



            string input = Console.ReadLine();

            do
            {
                if (input == "1")
                {
                    DisplayPokemonTable(myDex.pokemonList);
                    Console.WriteLine();
                    Console.WriteLine("Please enter the numbers beside the pokemon you wish to add to the list with a space between each number:");
                    bool correctNumber = false;

                    do
                    {
                        string   newTeam   = Console.ReadLine();
                        string[] teamsplit = newTeam.Split(' ');
                        if (teamsplit.Length < 6)
                        {
                            Console.WriteLine("Not enough pokemon have been added. try again:");
                            correctNumber = false;
                        }
                        else if (teamsplit.Length > 6)
                        {
                            Console.WriteLine("to many pokemon have been added. please try again.");
                            correctNumber = false;
                        }
                        else
                        {
                            Console.WriteLine("Thank you. now writing team to memory.");
                            correctNumber = true;
                            team          = teamsplit;
                        }
                    }while (!correctNumber);

                    WriteTeamToMemory(team);
                }
                else if (input == "2")
                {
                    Console.WriteLine("Below is a list of your current team:");
                    foreach (var item in myPokemon)
                    {
                        Console.WriteLine("|{0}|{1}|", item.DexNumber, item.Name);
                    }

                    Console.WriteLine("please select which pokemon you wish to change.");
                    Console.WriteLine("enter between 1 - 6.");

                    int pokemonToChance = Convert.ToInt32(Console.ReadLine());

                    DisplayPokemonTable(myDex.pokemonList);
                    Console.WriteLine("please chooses a pokemon to add");
                    int chosePokemon = Convert.ToInt32(Console.ReadLine());

                    Pokemon temp = GetPokemon(pokemonToChance, myDex, chosePokemon);

                    //Incompleat section the new number needs to be added to the list so the new team can be displayed.

                    //
                }
                else if (input == "3")
                {
                }
                else if (input == "4")
                {
                    foreach (Pokemon p in myDex.pokemonList)
                    {
                        foreach (var item in team)
                        {
                            if (item == "" || item == null)
                            {
                                break;
                            }
                            if (p.DexNumber == Convert.ToInt32(item))
                            {
                                myPokemon.Add(p);
                            }
                        }
                    }
                    Console.WriteLine("Your current team is:");
                    foreach (var item in myPokemon)
                    {
                        Console.WriteLine("|{0}|{1}|", item.DexNumber, item.Name);
                    }
                }
                else if (input.ToUpper() == "EXIT")
                {
                    Environment.Exit(0);
                }
                Console.WriteLine("Would you like to do anything else?");
                input = Console.ReadLine();
            } while (input.ToUpper() != "EXIT");
        }