public void CreatePlayerNameTest()
 {
     Player player = new Player(3, 5);
     player.Name = "Pesho";
     string expected = "Pesho";
     Assert.AreEqual(expected, player.Name);
 }
        public void CompareWithOtherObject()
        {
            Player player = new Player(5, 7);
            ScoreBoard scoreBoard = new ScoreBoard();

            player.CompareTo(scoreBoard);
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="player">Player instance</param>
 /// <param name="renderer">IRender instance</param>
 /// <param name="controller">IControler instance</param>
 /// <param name="scoreBoard">Scoreboard instance</param>
 public Engine(Player player, IRenderer renderer, IController controller, ScoreBoard scoreBoard)
 {
     this.Player = player;
     this.Renderer = renderer;
     this.Controller = controller;
     this.ScoreBoard = scoreBoard;
 }
Esempio n. 4
0
 /// <summary>
 /// The method adds the name of the player when the game is over
 /// </summary>
 /// <param name="player">Player</param>
 public void Add(Player player)
 {
     Console.Write("Enter name: ");
     string name = Console.ReadLine();
     player.Name = name;
     this.Players.Add(player);
 }
        public void CompareWithNull()
        {
            Player player = new Player(5, 7);
            int actual = player.CompareTo(null);

            Assert.AreEqual(1, actual);
        }
Esempio n. 6
0
 public void OnlyOneNameTest()
 {
     Player testPlayer = new Player('*', 3, 3);
     testPlayer.Name = "Raly";
     var currName = testPlayer.Name;
     testPlayer.Name = "Player name";
 }
        public void CompareWithOtherPlayerWithSameMoves()
        {
            Player player = new Player(5, 7);
            Player player2 = new Player(2, 3);

            int actual = player.CompareTo(player2);

            Assert.AreEqual(0, actual);
        }
Esempio n. 8
0
        public void InitEngineTest()
        {
            Player player = new Player('*', 3, 3);
            IRenderer renderer = new ConsoleRenderer();
            IController controller = new KeyboardController();
            ScoreBoard scoreBoard = new ScoreBoard();

            Engine engine = new Engine(player, renderer, controller, scoreBoard);
        }
 public Engine(Labyrinth labyrinth)
 {
     this.sizeOfTheLabirynth = labyrinth.Size;
     this.startPositionX = this.sizeOfTheLabirynth / 2;
     this.startPositionY = this.sizeOfTheLabirynth / 2;
     this.labyrinth = labyrinth;
     this.scoreBoard = new ScoreBoard();
     this.player = new Player(this.startPositionX, this.startPositionY);
     this.IntroduceTheGame();
 }
Esempio n. 10
0
        public void UpdateTest()
        {
            Player testPlayer = new Player('*', 3, 3);
            testPlayer.Update(new Coords(2, 2));

            var expected = "2 2";
            var actual = testPlayer.Row + " " + testPlayer.Col;

            Assert.AreEqual(expected, actual);
        }
        public void CompareWithOtherPlayerWithMoreMoves()
        {
            Player player = new Player(5, 7);

            Player player2 = new Player(2, 3);
            player2.MoveDown();

            int actual = player.CompareTo(player2);

            Assert.AreEqual(-1, actual);
        }
        public Engine(int sizeOfTheLabirynth)
        {
            if (sizeOfTheLabirynth < 1)
            {
                throw new ArgumentException("The size of the labyrinth cannot be less than 1", "sizeOfTheLabyrinth");
            }

            this.sizeOfTheLabirynth = sizeOfTheLabirynth;
            this.startPositionX = sizeOfTheLabirynth / 2;
            this.startPositionY = sizeOfTheLabirynth / 2;
            this.labyrinth = new Labyrinth(sizeOfTheLabirynth);
            this.scoreBoard = new ScoreBoard();
            this.player = new Player(this.startPositionX, this.startPositionY);
            this.IntroduceTheGame();
        }
Esempio n. 13
0
        static void Main()
        {
            Console.WriteLine("Welcome to “Labirinth” game. Please try to escape. Use 'top' to view the top");
            Console.WriteLine("scoreboard, 'restart' to start a new game and 'exit' to quit the game.");

            ScoreBoard scoreBoard = new ScoreBoard();
            while (true)
            {
                IController keyboard = new KeyboardController();
                IRenderer renderer = new ConsoleRenderer();
                Player player = new Player('*', 3, 3);
                Engine engine = new Engine(player, renderer, keyboard, scoreBoard);

                engine.StartGame();
            }
        }
        public void UpdateScoreBoard(Player player)
        {
            if (this.scoreBoard.Count < 5)
            {
                this.scoreBoard.Add(player.Moves, player);
            }
            else
            {
                int worstScore = this.GetWorstScore();
                if (player.Moves <= worstScore)
                {
                    if (this.scoreBoard.ContainsKey(player.Moves) == false)
                    {
                        this.scoreBoard.Remove(worstScore);
                    }

                    this.scoreBoard.Add(player.Moves, player);
                }
            }
        }
Esempio n. 15
0
 public void BlockedCellCharTest()
 {
     Player testPlayer = new Player('X', 3, 3);
 }
Esempio n. 16
0
 public void EmptyCharTest()
 {
     Player testPlayer = new Player('\u0000', 3, 3);
 }
Esempio n. 17
0
 public void EmptyNameTest()
 {
     Player testPlayer = new Player('*', 3, 3);
     testPlayer.Name = string.Empty;
 }
        public void TestMoveUp()
        {
            Player player = new Player(5, 7);
            player.MoveUp();

            Assert.IsTrue(player.PositionX == 5 && player.PositionY == 6);
        }
        public void TestMoveRight()
        {
            Player player = new Player(5, 7);
            player.MoveRight();

            Assert.IsTrue(player.PositionX == 6 && player.PositionY == 7);
        }
Esempio n. 20
0
 public void NegativeColTest()
 {
     Player testPlayer = new Player('*', 3, -2);
     Assert.Fail("Had to throw an exception because of invalid col");
 }
        public void PrintScoreboardTwoPlayers()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            Player player1 = new Player(2, 3);
            player1.Name = "Pesho";
            scoreBoard.UpdateScoreBoard(player1);

            Player player2 = new Player(3, 4);
            player2.Name = "Gosho";
            scoreBoard.UpdateScoreBoard(player2);

            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);

                scoreBoard.PrintScore();

                StringBuilder expected = new StringBuilder();
                expected.AppendLine("1. Pesho --> 0");
                expected.AppendLine("1. Gosho --> 0");

                StringBuilder actual = new StringBuilder();
                string[] splitLines = sw.ToString().TrimEnd().Split('\r', '\n');
                for (int i = 0; i < splitLines.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(splitLines[i]))
                    {
                        actual.AppendLine(splitLines[i]);
                    }
                }

                Assert.AreEqual(expected.ToString(), actual.ToString());
            }
        }
        public void PrintScoreboardMoreThanFivePlayersWithDifferentScores()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            Player player1 = new Player(2, 3);
            player1.Name = "Pesho";
            scoreBoard.UpdateScoreBoard(player1);

            Player player2 = new Player(3, 4);
            player2.MoveDown();
            player2.Name = "Gosho";
            scoreBoard.UpdateScoreBoard(player2);

            Player player3 = new Player(3, 4);
            player3.MoveDown();
            player3.MoveDown();
            player3.Name = "Gesho";
            scoreBoard.UpdateScoreBoard(player3);

            Player player4 = new Player(3, 4);
            player4.MoveDown();
            player4.MoveDown();
            player4.MoveDown();
            player4.Name = "Nesho";
            scoreBoard.UpdateScoreBoard(player4);

            Player player6 = new Player(3, 4);
            player6.MoveDown();
            player6.MoveDown();
            player6.MoveDown();
            player6.MoveDown();
            player6.MoveDown();
            player6.Name = "Tosho";
            scoreBoard.UpdateScoreBoard(player6);

            Player player5 = new Player(3, 4);
            player5.MoveDown();
            player5.MoveDown();
            player5.MoveDown();
            player5.MoveDown();
            player5.Name = "Losho";
            scoreBoard.UpdateScoreBoard(player5);

            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);

                scoreBoard.PrintScore();

                StringBuilder expected = new StringBuilder();
                expected.AppendLine("1. Pesho --> 0");
                expected.AppendLine("2. Gosho --> 1");
                expected.AppendLine("3. Gesho --> 2");
                expected.AppendLine("4. Nesho --> 3");
                expected.AppendLine("5. Losho --> 4");

                StringBuilder actual = new StringBuilder();
                string[] splitLines = sw.ToString().TrimEnd().Split('\r', '\n');
                for (int i = 0; i < splitLines.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(splitLines[i]))
                    {
                        actual.AppendLine(splitLines[i]);
                    }
                }

                Assert.AreEqual(expected.ToString(), actual.ToString());
            }
        }
        public void CreatePlayerPositionTest()
        {
            Player player = new Player(4, 9);

            Assert.IsTrue(player.PositionX == 4 && player.PositionY == 9);
        }
Esempio n. 24
0
 public void NegativeRowTest()
 {
     Player testPlayer = new Player('*', -3, 2);
     Assert.Fail("Had to throw an exception because of invalid row");
 }
Esempio n. 25
0
        public void ToStringTest()
        {
            Player player = new Player('*', 3, 3);
            player.Name = "Player name";
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Players.Add(player);

            var expected = string.Format("{0} {1} --> {2}\r\n", 1, scoreBoard.Players[0].Name, 0);
            var actual = scoreBoard.ToString();

            Assert.AreEqual(expected, actual);
        }
 public void CreatePlayerNullName()
 {
     Player player = new Player(5, 7);
     player.Name = null;
 }
Esempio n. 27
0
 public void FreeCellCharTest()
 {
     Player testPlayer = new Player('-', 3, 3);
 }
 public void CreatePlayerWhitespaceName()
 {
     Player player = new Player(5, 7);
     player.Name = "  ";
 }
        private void ExecuteCommand(string command)
        {
            switch (command.ToUpper())
            {
                case "L":
                    {
                        this.Move(0, -1);
                        break;
                    }

                case "R":
                    {
                        this.Move(0, 1);
                        break;
                    }

                case "U":
                    {
                        this.Move(-1, 0);
                        break;
                    }

                case "D":
                    {
                        this.Move(1, 0);
                        break;
                    }

                case "RESTART":
                    {
                        this.player = new Player(this.startPositionX, this.startPositionY);
                        this.labyrinth = new Labyrinth(this.sizeOfTheLabirynth);
                        break;
                    }

                case "TOP":
                    {
                        this.scoreBoard.PrintScore();
                        break;
                    }

                case "EXIT":
                    {
                        break;
                    }

                default:
                    {
                        this.PrintInvalidInput();
                        break;
                    }
            }
        }