public void Test_Player_CompareTo()
 {
     Player player = new Player("Pesho", 123);
     Player player1 = new Player("Gosho", 124);
     int expected = -1;
     Assert.AreEqual(expected, player.CompareTo(player1));
 }
 public void Test_Player_WithoutName()
 {
     Player player = new Player("", 123);
     string name = "Anonymous";
     Assert.AreEqual(name, player.Name);
 }
 public void Test_Player_ToString()
 {
     Player player = new Player("Pesho", 123);
     string result = "Pesho : 123;";
     Assert.AreEqual(result, player.ToString());
 }
 public void Test_Player_Constructor()
 {
     Player player = new Player("Pesho", 123);
     string name = "Pesho";
     Assert.AreEqual(name, player.Name);
 }
Beispiel #5
0
        public void StartGame()
        {
            bool gameInProgress = true;
            while (gameInProgress)
            {
                this.GenerateTable();
                Command.PrintGameInitializeInfo();
                Console.SetCursorPosition(0, 9);
                this.gameField.PrintField();
                bool isSolved = this.IsGameSolved();
                while (!isSolved)
                {
                    Console.Write("Enter a number to move: ");
                    string command = Console.ReadLine();
                    int number = 0;

                    Console.SetCursorPosition(24, 16);
                    Console.Write(new string(' ', command.Length));

                    bool isMoveCommand = int.TryParse(command, out number);
                    if (isMoveCommand)
                    {
                        if (number >= 1 && number <= 15)
                        {
                            this.Move(number);
                            Console.SetCursorPosition(0, 9);
                            this.gameField.PrintField();
                        }
                        else
                        {
                            Command.DisplayIllegalBlinkMessage(24, 16, "Illegal Move!", 0, 16);
                        }
                    }
                    else
                    {
                        if (Command.CommandType(command) == Command.Commands.exit.ToString())
                        {
                            Console.SetCursorPosition(0, 17);
                            Command.PrintGameAboutInfo();
                            gameInProgress = false;
                            break;
                        }
                        else if (Command.CommandType(command) == Command.Commands.restart.ToString())
                        {
                            this.RestartGame();
                        }
                        else if (Command.CommandType(command) == Command.Commands.top.ToString())
                        {
                            Console.SetCursorPosition(0, 17);
                            Console.WriteLine(this.highScore.ToString());
                            Console.SetCursorPosition(0, 16);
                        }
                        else
                        {
                            Command.DisplayIllegalBlinkMessage(24, 16, "Illegal Command!", 0, 16);
                        }
                    }

                    isSolved = this.IsGameSolved();
                }

                if (isSolved)
                {
                    Console.SetCursorPosition(0, 17);
                    Console.WriteLine("Congratulations! You won the game in {0} moves.", this.movesCounter);

                    Console.Write("Please enter your name for the top scoreboard: ");

                    string nickname = Console.ReadLine();

                    Player player = new Player(nickname, this.movesCounter);

                    this.highScore.AddPlayer(player);
                    Console.SetCursorPosition(0, 19);
                    Console.WriteLine(this.highScore.ToString());
                    Console.Clear();
                }
            }
        }
 public void AddPlayer(Player player)
 {
     this.players.Add(player);
     this.players.Sort();
     this.DeleteAllExceptTopPlayers();
 }