Пример #1
0
        private void ClearGames()
        {
            ConsoleUtility.WriteLineAsHeading("Clear Games");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Clearing list of games...");
            Games = new List <Game>();
            ConsoleUtility.WriteLine("Complete");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Reseting player ratings");
            UpdatePlayerRatingsCore();
            ConsoleUtility.WriteLine("Complete");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating collection of games in spreadsheet...");
            ChessScoreboardAPI.UpdateGamesInSpreadsheet(Games);
            ConsoleUtility.WriteLine("Complete");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating collection of players in spreadsheet...");
            ChessScoreboardAPI.UpdateRatingsInSpreadsheet(Players);
            ConsoleUtility.WriteLine("Complete");

            Clear();
        }
        private void UnrecognizedCommand(string action)
        {
            ConsoleUtility.WriteLineAsHeading($"Unrecognized Action '{action}'!");

            ConsoleUtility.WriteLine("If you are unsure of what actions are available, please use the 'Help' action");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteHyphenLine();
        }
Пример #3
0
        private void ViewPlayers()
        {
            ConsoleUtility.WriteLineAsHeading("View Players");

            foreach (Player player in Players)
            {
                ConsoleUtility.WriteLine($"{player.CurrentRank}. {player.FirstName} is ranked #{player.CurrentRank} with an ELO rating of {player.Rating}");
            }

            ConsoleUtility.WriteHyphenLine();
        }
Пример #4
0
        private void ViewGames()
        {
            ConsoleUtility.WriteLineAsHeading("View Games");

            foreach (Game game in Games)
            {
                if (game.WasAStalemate)
                {
                    ConsoleUtility.WriteLine($"-- Game #{game.Id} was between {game.Winner.FirstName} and {game.Loser.FirstName}. The outcome was a draw!");
                }
                else
                {
                    ConsoleUtility.WriteLine($"-- Game #{game.Id} was between {game.Winner.FirstName} and {game.Loser.FirstName}. The outcome was a win for {game.Winner.FirstName}!");
                }
            }

            ConsoleUtility.WriteHyphenLine();
        }
Пример #5
0
        private void AddPlayer()
        {
            ConsoleUtility.WriteLineAsHeading("Add Player");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("What is the name of the player you would like to add?");

            string playerName = ConsoleUtility.ReadLine();

            var player = new Player(Players.Max(p => p.CurrentRank) + 1, Constants.BaseRating, playerName);

            Players.Add(player);

            ChessScoreboardAPI.UpdatePlayersInSpreadsheet(Players);

            Clear();
            ViewPlayers();
        }
Пример #6
0
        private void UpdatePlayerRatings()
        {
            ConsoleUtility.WriteLineAsHeading("Update Player Ratings");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating Player Ratings...");

            UpdatePlayerRatingsCore();

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating the Spreadsheet with the new Player Ratings...");
            ChessScoreboardAPI.UpdateRatingsInSpreadsheet(Players);

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Update Complete");

            Clear();
            ViewPlayers();
        }
Пример #7
0
        private void Help()
        {
            ConsoleUtility.WriteLineAsHeading("Help Information");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Available Actions");
            ConsoleUtility.WriteHyphenLine("Available Actions");
            ConsoleUtility.WriteLine();

            foreach (UserAction userAction in UserActions)
            {
                string summary = $"-- Action: '{userAction.Name}' | Description: '{userAction.Description}'";
                ConsoleUtility.WriteHyphenLine(summary);
                ConsoleUtility.WriteLine(summary);

                if (userAction.Aliases.Any())
                {
                    ConsoleUtility.WriteLine($"-- \t Action Aliases: '{string.Join(", ", userAction.Aliases.ToArray())}'");
                }
            }

            ConsoleUtility.WriteHyphenLine();

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Available Answers to Yes/No Questions (Anything not on the list is treated as a no)");
            ConsoleUtility.WriteHyphenLine("Available Answers to Yes/No Questions (Anything not on the list is treated as a no)");

            foreach (string acceptableYesAnswer in ConsoleUtility.AcceptableYesAnswers)
            {
                ConsoleUtility.WriteLine($"-- {acceptableYesAnswer}");
            }

            ConsoleUtility.WriteLine();

            ConsoleUtility.WriteHyphenLine();
            ConsoleUtility.WriteLine("For more information, send me an email at [email protected]");
            ConsoleUtility.WriteHyphenLine();
        }
Пример #8
0
        private void AddGame()
        {
            ConsoleUtility.WriteLineAsHeading("Add Game");

            var game = new Game();

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Was the game a stalemate?");
            game.WasAStalemate = ConsoleUtility.ReadYesNoAnswer();

            ConsoleUtility.WriteHyphenLine();
            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Avaiable Players");
            ConsoleUtility.WriteHyphenLine("Avaiable Players");

            foreach (Player player in Players)
            {
                ConsoleUtility.WriteLine($"{player.CurrentRank}. {player.FirstName}");
            }

            ConsoleUtility.WriteHyphenLine();

            int winnerNumber, loserNumber;

            if (game.WasAStalemate)
            {
                ConsoleUtility.WriteLine();
                ConsoleUtility.WriteLine("In the above list, what number was player one?");
                winnerNumber = ConsoleUtility.ReadInt();

                ConsoleUtility.WriteLine();
                ConsoleUtility.WriteLine("In the above list, what number was player two?");
                loserNumber = ConsoleUtility.ReadInt();
            }
            else
            {
                ConsoleUtility.WriteLine();
                ConsoleUtility.WriteLine("In the above list, what number was the winner?");
                winnerNumber = ConsoleUtility.ReadInt();

                ConsoleUtility.WriteLine();
                ConsoleUtility.WriteLine("In the above list, what number was the loser?");
                loserNumber = ConsoleUtility.ReadInt();
            }

            Player winner, loser;

            winner = Players.FirstOrDefault(player => player.CurrentRank == winnerNumber);
            loser  = Players.FirstOrDefault(player => player.CurrentRank == loserNumber);

            while (winner == null || loser == null)
            {
                Clear();

                ConsoleUtility.WriteHyphenLine();
                ConsoleUtility.WriteLine("Unable to find one or both of the players for the numbers specified. If you do not see a player in the list please add one using the add player action");
                ConsoleUtility.WriteLine("Try again?");
                bool tryAgain = ConsoleUtility.ReadYesNoAnswer();

                if (tryAgain)
                {
                    if (game.WasAStalemate)
                    {
                        ConsoleUtility.WriteLine();
                        ConsoleUtility.WriteLine("In the above list, what number was player one?");
                        winnerNumber = ConsoleUtility.ReadInt();

                        ConsoleUtility.WriteLine();
                        ConsoleUtility.WriteLine("In the above list, what number was player two?");
                        loserNumber = ConsoleUtility.ReadInt();
                    }
                    else
                    {
                        ConsoleUtility.WriteLine();
                        ConsoleUtility.WriteLine("In the above list, what number was the winner?");
                        winnerNumber = ConsoleUtility.ReadInt();

                        ConsoleUtility.WriteLine();
                        ConsoleUtility.WriteLine("In the above list, what number was the loser?");
                        loserNumber = ConsoleUtility.ReadInt();
                    }

                    winner = Players.FirstOrDefault(player => player.CurrentRank == winnerNumber);
                    loser  = Players.FirstOrDefault(player => player.CurrentRank == loserNumber);
                }
                else
                {
                    Clear();
                    return;
                }
            }

            game.Winner = winner;
            game.Loser  = loser;

            Games.Add(game);

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating ratings based on added game...");
            UpdatePlayerRatingsCore();
            ConsoleUtility.WriteLine("Complete");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating collection of games in spreadsheet...");
            ChessScoreboardAPI.UpdateGamesInSpreadsheet(Games);
            ConsoleUtility.WriteLine("Complete");

            ConsoleUtility.WriteLine();
            ConsoleUtility.WriteLine("Updating collection of players in spreadsheet...");
            ChessScoreboardAPI.UpdateRatingsInSpreadsheet(Players);
            ConsoleUtility.WriteLine("Complete");

            Clear();
        }