예제 #1
0
        public void TestIsPlayerTop4TopPlayers()
        {
            Player player1 = new Player("Ivan", 0);
            Player player2 = new Player("Maria", 1);
            Player player3 = new Player("Georgi", 2);
            Player player4 = new Player("Gergana", 5);

            ScoreManager manager = ScoreManager.Instance;

            manager.AddPlayerToScoreBoard(player1);
            manager.AddPlayerToScoreBoard(player2);
            manager.AddPlayerToScoreBoard(player3);
            manager.AddPlayerToScoreBoard(player4);

            Player newPlayer = new Player("Pesho", 10);
            Assert.IsTrue(manager.IsPlayerTop(newPlayer.Mistakes));
        }
예제 #2
0
 public void AddPlayerToScoreBoard(Player player)
 {
     if (topPlayers.Count < MaxNumberOFPlayers)
     {
         topPlayers.Add(player);
     }
     else
     {
         for (int i = 0; i < topPlayers.Count; i++)
         {
             if (topPlayers[i].Mistakes > player.Mistakes)
             {
                 topPlayers.Insert(i, player);
                 topPlayers.RemoveAt(topPlayers.Count - 1);
                 break;
             }
         }
     }
     SortPlayers();
 }
예제 #3
0
        public void TestAddPlayerToScoreboard()
        {
            Player player1 = new Player("Ivan", 0);
            Player player2 = new Player("Maria", 1);
            Player player3 = new Player("Georgi", 2);
            Player player4 = new Player("Gergana", 5);
            Player player5 = new Player("Gosho", 3);
            Player newPlayer = new Player("Pesho", 4);

            ScoreManager manager = ScoreManager.Instance;

            manager.AddPlayerToScoreBoard(player1);
            manager.AddPlayerToScoreBoard(player2);
            manager.AddPlayerToScoreBoard(player3);
            manager.AddPlayerToScoreBoard(player4);
            manager.AddPlayerToScoreBoard(player5);
            manager.AddPlayerToScoreBoard(newPlayer);

            Assert.IsTrue(manager.TopPlayers.Contains(newPlayer));
            Assert.IsFalse(manager.TopPlayers.Contains(player4));
        }
예제 #4
0
        private void HandleLetterGuess(char guessedLetter, LetterStatus letterStatus)
        {
            switch (letterStatus)
            {
                case LetterStatus.Correct:
                    if (!IsWordGuessed())
                    {
                        this.renderer.PrintCorrectLetterMessage(this.letterHandler.GuessedLettersCount);
                    }
                    else
                    {
                        if (this.UsedHelp)
                        {
                            this.renderer.PrintCheatingMessage(this.letterHandler.WrongLettersCount);
                            this.renderer.PrintWordToDisplayMessage(this.WordToDisplay);
                        }
                        else
                        {
                            this.renderer.PrintWinningMessage(this.letterHandler.WrongLettersCount);
                            this.renderer.PrintWordToDisplayMessage(this.WordToDisplay);

                            if (this.scoreManager.IsPlayerTop(this.letterHandler.WrongLettersCount))
                            {
                                this.renderer.PrintGetNameForScoreboard();
                                string playerName = Console.ReadLine();
                                int playerMistakes = this.letterHandler.WrongLettersCount;
                                Player player = new Player(playerName, playerMistakes);
                                this.scoreManager.AddPlayerToScoreBoard(player);
                            }

                            this.renderer.PrintScoreboard(this.scoreManager.TopPlayers);
                        }

                        this.RestartGame();
                    }
                    break;

                case LetterStatus.Incorrect:
                    this.renderer.PrintIncorrectLetterMessage(guessedLetter);
                    break;

                case LetterStatus.Repeating:
                    this.renderer.PrintRepeatingLetterMessage(guessedLetter);
                    break;
                default:
                    break;
            }
        }