Ejemplo n.º 1
0
        public void TestDeleteAllExceptTopFivePlayers()
        {
            Scoreboard.ClearPlayer();
            Player player1 = new Player("Ivan", 21);

            Scoreboard.AddPlayer(player1);
            Assert.IsTrue(Scoreboard.Count <= 5);
        }
Ejemplo n.º 2
0
        public void TestAddPlayerWithThreeAddedPlayers()
        {
            Scoreboard.ClearPlayer();
            Player player1 = new Player("Ivan", 21);

            Scoreboard.AddPlayer(player1);
            Player player2 = new Player("Petar", 12);

            Scoreboard.AddPlayer(player2);
            Player player3 = new Player("Petya", 24);

            Scoreboard.AddPlayer(player3);
            Assert.AreEqual(3, Scoreboard.Count);
        }
Ejemplo n.º 3
0
        public void TestCheckPlayersScoresSmallerThanOthers()
        {
            Scoreboard.ClearPlayer();
            Player player1 = new Player("Ivan", 21);

            Scoreboard.AddPlayer(player1);
            Player player2 = new Player("Petar", 12);

            Scoreboard.AddPlayer(player2);
            Player player3 = new Player("Petya", 24);

            Scoreboard.AddPlayer(player3);
            Player player4 = new Player("Mimi", 12);

            Scoreboard.AddPlayer(player4);
            Player player5 = new Player("Gosho", 17);

            Scoreboard.AddPlayer(player5);
            bool isScoresSmalerThanOtherPlayersScores = Scoreboard.CheckPlayerScores(10);

            Assert.IsTrue(isScoresSmalerThanOtherPlayersScores);
        }
Ejemplo n.º 4
0
        public void TestDeleteAllExceptTopFivePlayersMorePlayers()
        {
            Scoreboard.ClearPlayer();
            Player player1 = new Player("Ivan", 21);

            Scoreboard.AddPlayer(player1);
            Player player2 = new Player("Petar", 12);

            Scoreboard.AddPlayer(player2);
            Player player3 = new Player("Petya", 24);

            Scoreboard.AddPlayer(player3);
            Player player4 = new Player("Mimi", 12);

            Scoreboard.AddPlayer(player4);
            Player player5 = new Player("Gosho", 17);

            Scoreboard.AddPlayer(player5);
            Player player6 = new Player("Yordan", 27);

            Scoreboard.AddPlayer(player6);
            Assert.IsTrue(Scoreboard.Count <= 5);
        }
Ejemplo n.º 5
0
        private static void Menu()
        {
            List <Tile> tiles = new List <Tile>();
            int         cnt   = 0;
            string      s     = "restart";
            bool        flag  = false;

            while (s != "exit")
            {
                if (!flag)
                {
                    switch (s)
                    {
                    case "restart":
                    {
                        string welcomeMessage = "Welcome to the game “15”. Please try to arrange the numbers sequentially. ";
                        welcomeMessage = welcomeMessage + "\nUse 'top' to view the top scoreboard, 'restart' to start a new game and 'exit'";
                        welcomeMessage = welcomeMessage + " \nto quit the game.";
                        Console.WriteLine();
                        Console.WriteLine(welcomeMessage);
                        tiles = MatrixGenerator.GenerateMatrix();
                        tiles = MatrixGenerator.ShuffleMatrix(tiles);
                        flag  = Gameplay.IsMatrixSolved(tiles);
                        Gameplay.PrintMatrix(tiles);
                        break;
                    }

                    case "top":
                    {
                        Scoreboard.PrintScoreboard();
                        break;
                    }
                    }
                    if (!flag)
                    {
                        Console.Write("Enter a number to move: ");
                        s = Console.ReadLine();

                        int destinationTileValue;

                        bool isSuccessfulParsing = Int32.TryParse(s, out destinationTileValue);

                        if (isSuccessfulParsing)
                        {
                            try
                            {
                                Gameplay.MoveTiles(tiles, destinationTileValue);
                                cnt++;
                                Gameplay.PrintMatrix(tiles);
                                flag = Gameplay.IsMatrixSolved(tiles);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine(exception.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                s = Command.CommandType(s);
                            }
                            catch (ArgumentException exception)
                            {
                                Console.WriteLine(exception.Message);
                            }
                        }
                    }
                }
                else
                {
                    if (cnt == 0)
                    {
                        Console.WriteLine("Your matrix was solved by default :) Come on - NEXT try");
                    }
                    else
                    {
                        Console.WriteLine("Congratulations! You won the game in {0} moves.", cnt);
                        Console.Write("Please enter your name for the top scoreboard: ");
                        string playerName = Console.ReadLine();
                        Player player     = new Player(playerName, cnt);
                        Scoreboard.AddPlayer(player);
                        Scoreboard.PrintScoreboard();
                    }
                    s    = "restart";
                    flag = false;
                    cnt  = 0;
                }
            }
        }