public void CompareToShouldReturnCorrectNumberWhenComparingPlayerScoresWithEqualGuesses()
        {
            PlayerScore score1 = new PlayerScore("Score1", 2);
            PlayerScore score2 = new PlayerScore("Score2", 2);

            int actual = score1.CompareTo(score2);
            int expected = -1;

            Assert.AreEqual(expected, actual, "CompareTo doesn't return correct integer when comparing two PlayerScores with equal guesses");
        }
        public override bool Equals(object obj)
        {
            PlayerScore objectToCompare = obj as PlayerScore;

            if (objectToCompare == null)
            {
                return(false);
            }
            else
            {
                return(this.Guesses.Equals(objectToCompare) &&
                       this.PlayerName.Equals(objectToCompare));
            }
        }
示例#3
0
        /// <summary>
        /// Adds new <see cref="PlayerScore"/> to <see cref="ScoreBoard"/>
        /// </summary>
        /// <param name="playerScore">PlayerScore to be added.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when null is inputted.</exception>
        public void Add(PlayerScore playerScore)
        {
            if (playerScore == null)
            {
                throw new ArgumentNullException("Can't add null in scoreboard.");
            }

            this.playerScores.Add(playerScore);
            this.SortPlayerScores();

            if (this.playerScores.Count > MaxPlayerScores)
            {
                this.playerScores.RemoveAt(this.playerScores.Count - 1);
            }
        }
        public int CompareTo(object obj)
        {
            PlayerScore objectToCompare = obj as PlayerScore;

            if (objectToCompare == null)
            {
                throw new ArgumentNullException("Player score to compare to is null!");
            }

            if (this.Guesses.CompareTo(objectToCompare.Guesses) == 0)
            {
                return(this.PlayerName.CompareTo(objectToCompare.PlayerName));
            }
            else
            {
                return(this.Guesses.CompareTo(objectToCompare.Guesses));
            }
        }
 public ScoreBoard(string filename)
 {
     this.scores = new SortedSet <PlayerScore>();
     try
     {
         using (StreamReader inputStream = new StreamReader(filename))
         {
             while (!inputStream.EndOfStream)
             {
                 string scoreString = inputStream.ReadLine();
                 this.scores.Add(PlayerScore.Deserialize(scoreString));
             }
         }
     }
     catch (IOException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        /// <summary>
        /// Adds player score.
        /// </summary>
        /// <param name="playerScore">Player score.</param>
        public void AddPlayerScore(PlayerScore playerScore)
        {
            StreamWriter scoresWriter = new StreamWriter(FilePath, true);

            using (scoresWriter)
            {
                scoresWriter.WriteLine(ScoreWriterFormatText, playerScore.NickName, playerScore.Guesses);
            }

            this.leaderBoard.Add(playerScore);
        }
        public void AddScore(string name, int guesses)
        {
            PlayerScore newScore = new PlayerScore(name, guesses);

            this.scores.Add(newScore);
        }
 public void TestWithZeroAttempts()
 {
     PlayerScore playerScore = new PlayerScore("John", 0);
 }
 public void PlayerScoreShouldThrowArgumentExceptionWhenInitializedWithWhitespaceForName()
 {
     PlayerScore playerScore = new PlayerScore("  ", 3);
 }
 public void TestWithNullName()
 {
     PlayerScore playerScore = new PlayerScore(null, 15);
 }
 public void TestWithNegativeAttempts()
 {
     PlayerScore playerScore = new PlayerScore("John", -3);
 }
 public void TestWithEmptyName()
 {
     PlayerScore playerScore = new PlayerScore("", 15);
 }
 public void TestNameGetter()
 {
     PlayerScore playerScore = new PlayerScore("Johnny", 11);
     Assert.AreEqual("Johnny", playerScore.Name);
 }
 public void TestAttemptsGetter()
 {
     PlayerScore playerScore = new PlayerScore("Johnny", 13);
     Assert.AreEqual(13, playerScore.Attempts);
 }
 public void AddScore(string name, int guesses)
 {
     PlayerScore newScore = new PlayerScore(name, guesses);
     this.scores.Add(newScore);
 }
 public void PlayerScoreShouldThrowArgumentExceptionWhenInitializedWithEmptyStringForName()
 {
     PlayerScore playerScore = new PlayerScore(string.Empty, 3);
 }
 public void PlayerScoreShouldThrowArgumentExceptionWhenInitializedWithNullStringForName()
 {
     PlayerScore playerScore = new PlayerScore(null, 3);
 }
 public void TestWithValidData()
 {
     PlayerScore playerScore = new PlayerScore("John", 15);
     Assert.AreNotEqual(null, playerScore);
 }
        public void ToStringShouldReturnCorrectFormatMessage()
        {
            PlayerScore score = new PlayerScore("Player", 2);

            string actual = score.ToString();
            string expected = string.Format("{0,3}    | {1}", score.Guesses, score.NickName);

            Assert.AreEqual(expected, actual, "StringTo doesn't return proper formatted string");
        }
 public void TestWithWhiteSpaceName()
 {
     PlayerScore playerScore = new PlayerScore("    \n\t", 15);
 }