コード例 #1
0
        public static void Main(string[] args)
        {
            string selection = "";

            if (!TournamentList.Tournaments.Any())
            {
                GetTournamentData.GetData();
            }
            if (!PlayerList.Players.Any())
            {
                GetPlayerData.GetData();
            }

            while (!(selection == "4"))
            {
                Console.Clear();
                Console.WriteLine("Select an option:\n ");
                Console.WriteLine("1: Tournaments");
                Console.WriteLine("2: Players");
                Console.WriteLine("3: Overall Stats");
                Console.WriteLine("4: Save & Quit");
                selection = Console.ReadLine();

                if (selection == "1")
                {
                    TournamentList.ViewTournaments();
                }
                else if (selection == "2")
                {
                    PlayerList.ViewPlayers();
                }
                else if (selection == "3")
                {
                    Console.WriteLine("Overall Stats.");
                }
            }
        }
コード例 #2
0
        public static void ViewPlayers()
        {
            string selection     = "";
            int    displayed     = 0;
            int    displayAmount = 10;
            double pages;
            int    page;

            GetPlayerData.GetData();

            while (!(selection == "q"))
            {
                Console.Clear();
                Console.WriteLine("Select a player by league number:\n");

                //Allow using "next" if not at the end of the list of players
                if (displayed < PlayerList.Players.Count - displayAmount)
                {
                    if (selection == "n")
                    {
                        displayed += displayAmount;
                    }
                }

                //allow using "back" if not at the beginning of the list of players
                if (displayed >= displayAmount)
                {
                    if (selection == "b")
                    {
                        displayed -= displayAmount;
                    }
                }

                //gets total pages and current page
                pages = Math.Ceiling(Convert.ToDouble(PlayerList.Players.Count) / displayAmount);
                page  = displayed / displayAmount + 1;

                //Prevent errors when the end of the list is reached
                try
                {
                    //Print information for players in display range
                    foreach (int i in Enumerable.Range(displayed, displayAmount))
                    {
                        Console.WriteLine(PlayerList.Players[i].LeagueNumber + " " + PlayerList.Players[i].Name);
                    }
                }
                catch
                {
                    //Maybe notify user of end of list?
                }

                int playerIndex = -1;

                //displays page information
                Console.WriteLine("\nPage {0}/{1}", page.ToString(), pages.ToString());

                Console.WriteLine("\n[n] Next [b] Back [q] quit\n[new] new player");

                selection = Console.ReadLine();

                if (selection == "new")
                {
                    NewPlayer();
                }

                //Select a player with SelectPlayer if their league number is entered

                playerIndex = PlayerList.Players.FindIndex(thisPlayer => thisPlayer.LeagueNumber == selection);

                if (playerIndex != -1)
                {
                    Player.SelectPlayer(PlayerList.Players[playerIndex]);
                }
                else
                {
                    if (selection != "n" && selection != "b" && selection != "q" && selection != "new")
                    {
                        Console.WriteLine("Invalid Player");
                    }
                }
            }
        }