public void CompareWithOtherObject()
        {
            Player player = new Player(5, 7);
            ScoreBoard scoreBoard = new ScoreBoard();

            player.CompareTo(scoreBoard);
        }
Beispiel #2
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;
 }
Beispiel #3
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();
 }
        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();
        }
Beispiel #6
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 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 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 PrintScoreboardZeroPlayers()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

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

                scoreBoard.PrintScore();

                string expected = "The scoreboard is empty.";
                var result = sw.ToString().TrimEnd();
                Assert.AreEqual(expected, result);
            }
        }