Exemplo n.º 1
0
 public void Player_MaxScoreValue_Set()
 {
     Player testPlayer = new Player();
     int input = int.MaxValue;
     testPlayer.Score = input;
     Assert.AreEqual(input, testPlayer.Score);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public void Player_ComparisonOperator_Smaller()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     Player secondPlayer = new Player();
     secondPlayer.Score = 2;
     Assert.IsTrue(firstPlayer < secondPlayer);
 }
Exemplo n.º 4
0
 public void Player_ComparisonOperator_Bigger()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     Player secondPlayer = new Player();
     secondPlayer.Score = 2;
     Assert.IsFalse(firstPlayer > secondPlayer);
 }
Exemplo n.º 5
0
 private static void Add12345ToTopScoreList(TopScore topScore)
 {
     for (int i = 1; i <= 5; i++)
     {
         Player player = new Player();
         player.Score = i;
         topScore.AddToTopScoreList(player);
     }
 }
Exemplo n.º 6
0
 public static void AddToTopScoreList(Player person)
 {
     TopScoreList.Add(person);
     TopScoreList.Sort();
     while (TopScoreList.Count > 5)
     {
         TopScoreList.RemoveAt(5);
     }
 }
Exemplo n.º 7
0
        public void MaxTopScoreCount()
        {
            Player testPlayer = new Player();

            for (int i = 0; i < 7; i++)
            {
                testPlayer.Name = "Name " + i;
                testPlayer.Score = i;
                TopScore.IsTopScore(testPlayer);
            }
        }
Exemplo n.º 8
0
        public void IsTopScore_ValidInput_Test()
        {
            TopScore.Instance.Clear();
            TopScore newTopScore = new TopScore();
            Add12345ToTopScoreList(newTopScore);

            Player testPlayer = new Player();
            testPlayer.Score = 0;
            bool result = newTopScore.IsTopScore(testPlayer);
            Assert.IsTrue(result);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public static bool IsTopScore(Player person)
        {
            if (TopScoreList.Count >= MAX_TOP_SCORE_COUNT)
            {
                int lastTopScorePlayer = MAX_TOP_SCORE_COUNT - 1;
                TopScoreList.Sort();
                if (TopScoreList[lastTopScorePlayer] > person)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        public static void OpenTopScoreList()
        {
            using (StreamReader topScoreStreamReader = new StreamReader("..\\..\\TopScore.txt"))
            {
                string line = topScoreStreamReader.ReadLine();
                while (line != null)
                {
                    char[] separators = { ' ' };
                    string[] substrings = line.Split(separators);
                    int substringsCount = substrings.Count<string>();

                    if (substringsCount > 0)
                    {
                        Player player = new Player();
                        player.Name = substrings[1];
                        player.Score = int.Parse(substrings[substringsCount - 2]);
                        TopScoreList.Add(player);
                    }

                    line = topScoreStreamReader.ReadLine();
                }
            }
        }
Exemplo n.º 13
0
 public void Player_ValidName_Set()
 {
     Player testPlayer = new Player();
     string input = "Natalya";
     testPlayer.Name = input;
     Assert.AreEqual(input, testPlayer.Name);
 }
Exemplo n.º 14
0
 public void Player_InValidCompareToMethod_Test()
 {
     Player firstPlayer = new Player();
     firstPlayer.Score = 1;
     firstPlayer.CompareTo(4);
 }
Exemplo n.º 15
0
 public void Player_NegativeScoreValue_Set()
 {
     Player testPlayer = new Player();
     int input = -5;
     testPlayer.Score = input;
 }
Exemplo n.º 16
0
 public void Player_NullNameValue_Set()
 {
     Player testPlayer = new Player();
     string input = null;
     testPlayer.Name = input;
 }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        static void Main()
        {
            Console.WriteLine("Welcome to “Balloons Pops” game. Please try to pop the balloons. Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game.");
            
            GameBoard gameBoard = new GameBoard();
            gameBoard.GenerateNewGameBoard();

            Console.WriteLine(gameBoard.ToString());

            TopScore.OpenTopScoreList();
            
            bool isCoordinates;
            Coordinates coordinates = new Coordinates();
            Command command = new Command();

            while (gameBoard.RemainingBaloons > 0)
            {
                if (ReadInput(out isCoordinates, ref coordinates, ref command))
                {
                    if (isCoordinates)
                    {
                        try
                        {
                            gameBoard.ShootBaloons(coordinates);
                        }
                        catch (PopedBallonException exp)
                        {
                            Console.WriteLine(exp.Message);
                        }
                        
                        Console.WriteLine(gameBoard.ToString());
                    }
                    else
                    {
                        switch (command.Value)
                        {
                            case "top":
                                {
                                    TopScore.PrintScoreList();
                                }
                                break;
                            case "restart":
                                {
                                    gameBoard.GenerateNewGameBoard();
                                    Console.WriteLine(gameBoard.ToString());
                                }
                                break;
                            case "exit":
                                {
                                    return;
                                }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Wrong Input!");
                }
            }

            Player player = new Player();
            player.Score = gameBoard.ShootCounter;

            if (TopScore.IsTopScore(player))
            {
                Console.WriteLine("Please enter your name for the top scoreboard: ");
                player.Name = Console.ReadLine();
                TopScore.AddToTopScoreList(player);
            }
            TopScore.SaveTopScoreList();
            TopScore.PrintScoreList();
        }
Exemplo n.º 19
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();
        }