示例#1
0
 public void Player_ValidName_Set()
 {
     Player testPlayer = new Player();
     string input = "Natalya";
     testPlayer.Name = input;
     Assert.AreEqual(input, testPlayer.Name);
 }
示例#2
0
 public void Player_MaxScoreValue_Set()
 {
     Player testPlayer = new Player();
     int input = int.MaxValue;
     testPlayer.Score = input;
     Assert.AreEqual(input, testPlayer.Score);
 }
示例#3
0
 public void Player_ComparisonOperator_Bigger()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     Player secondPlayer = new Player();
     secondPlayer.Score = 2;
     Assert.IsFalse(firstPlayer > secondPlayer);
 }
示例#4
0
 public void Player_ComparisonOperator_Smaller()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     Player secondPlayer = new Player();
     secondPlayer.Score = 2;
     Assert.IsTrue(firstPlayer < secondPlayer);
 }
示例#5
0
 public void IsTopScore_ListNotFull_Test()
 {
     TopScore.Instance.Clear();
     Player testPlayer = new Player();
     testPlayer.Score = 9;
     bool result = TopScore.Instance.IsTopScore(testPlayer);
     Assert.IsTrue(result);
 }
示例#6
0
 private static void Add12345ToTopScoreList(TopScore topScore)
 {
     for (int i = 1; i <= 5; i++)
     {
         Player player = new Player();
         player.Score = i;
         topScore.AddToTopScoreList(player);
     }
 }
示例#7
0
        public void IsTopScore_InValidInput_Test()
        {
            TopScore.Instance.Clear();
            TopScore newTopScore = new TopScore();
            Add12345ToTopScoreList(newTopScore);

            Player testPlayer = new Player();
            testPlayer.Score = 9;
            bool result = newTopScore.IsTopScore(testPlayer);
            Assert.IsFalse(result);
        }
示例#8
0
        public void AddToTopScoreList_ValidInput_Test()
        {
            TopScore.Instance.Clear();
            Add12345ToTopScoreList(TopScore.Instance);

            Player testPlayer = new Player();
            testPlayer.Score = 3;
            TopScore.Instance.AddToTopScoreList(testPlayer);

            bool result = (TopScore.Instance.TopScoreList.Count > 5);
            Assert.IsFalse(result);
        }
示例#9
0
        /// <summary>
        /// Checks if person is among top score players
        /// </summary>
        /// <param name="person">Player to check is top scored</param>
        /// <returns>
        /// True if person is top score player
        /// False if person is not a top score player
        /// </returns>
        public bool IsTopScore(Player person)
        {
            if (topScoreList.Count >= MaxTopScoreCount)
            {
                int lastTopScorePlayer = MaxTopScoreCount - 1;
                topScoreList.Sort();
                if (topScoreList[lastTopScorePlayer] > person)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return true;
        }
示例#10
0
        public void Player_ValidCompareToMethod_Test()
        {
            List<Player> scoreList = new List<Player>();

            Player firstPlayer = new Player();
            firstPlayer.Score = 3;
            scoreList.Add(firstPlayer);

            Player secondPlayer = new Player();
            secondPlayer.Score = 1;
            scoreList.Add(secondPlayer);

            Player thirdPlayer = new Player();
            thirdPlayer.Score = 2;
            scoreList.Add(thirdPlayer);

            scoreList.Sort();

            for (int playerIndex = 0; playerIndex < scoreList.Count; playerIndex++)
            {
                Assert.AreEqual(playerIndex + 1, scoreList[playerIndex].Score);
            }
        }
示例#11
0
 public void Player_InValidCompareToMethod_Test()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     firstPlayer.CompareTo(4);
 }
示例#12
0
 public void Player_NegativeScoreValue_Set()
 {
     Player testPlayer = new Player();
     int input = -5;
     testPlayer.Score = input;
 }
示例#13
0
 public void Player_NullNameValue_Set()
 {
     Player testPlayer = new Player();
     string input = null;
     testPlayer.Name = input;
 }
示例#14
0
 /// <summary>
 /// Adds a player to top score list
 /// </summary>
 /// <param name="person">Top score player</param>
 public void AddToTopScoreList(Player person)
 {
     topScoreList.Add(person);
     topScoreList.Sort();
     while (topScoreList.Count > 5)
     {
         topScoreList.RemoveAt(5);
     }
 }
示例#15
0
        /// <summary>
        /// Loads top score list from file into the program memory
        /// </summary>
        public void OpenTopScoreList()
        {
            using (StreamReader topScoreStreamReader = new StreamReader(FilePath))
            {
                string line = topScoreStreamReader.ReadLine();
                while (line != null)
                {
                    char[] separators = { ' ' };
                    string[] substrings = line.Split(separators);
                    int substringsCount = substrings.Count<string>();

                    if (substringsCount > 0)
                    {
                        string playerName = substrings[1];
                        string playerScore = substrings[substringsCount - 2];
                        Player player = new Player();
                        player.Name = playerName;
                        player.Score = int.Parse(playerScore);

                        topScoreList.Add(player);
                    }

                    line = topScoreStreamReader.ReadLine();
                }
            }
        }
示例#16
0
        /// <summary>
        /// Check if player is Top Scorer and if true add him/her to Top Scored Players
        /// </summary>
        private void CheckTopScore()
        {
            Player player = new Player();
            player.Score = this.gameBoardManager.ShootCounter;

            if (TopScore.Instance.IsTopScore(player))
            {
                Console.WriteLine("Please enter your name for the top scoreboard: ");
                string playerName = Console.ReadLine();
                player.Name = playerName;
                TopScore.Instance.AddToTopScoreList(player);
            }

            TopScore.Instance.SaveTopScoreList();
            TopScore.Instance.PrintScoreList();
        }