Пример #1
0
        public void CreateEngineAndEnterInvalidCoordinates()
        {
            Engine engine = new Engine(5, 10);
            engine.RunGame();

            Console.SetIn(new System.IO.StringReader("44 9"));
            engine.ReadAction();
            CurrentAction expected = CurrentAction.IsWaitingForValidInput;
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("aa bb"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("2100 02100"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("12 31321"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("noone"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("tests"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("a b"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);
        }
        public void AddPlayersToScoreBoard()
        {
            Engine engine = new Engine(5, 10);
            ScoreBoard scoreBoard = new ScoreBoard();
            Assert.IsNotNull(scoreBoard);

            Player misho = new Player(0, "misho");
            Assert.IsNotNull(misho);

            Player stefan = new Player();
            Assert.IsNotNull(stefan);

            Player carl = new Player(0, "Carl");
            Assert.IsNotNull(carl);

            Player pepo = new Player(0, "Pepito");
            Assert.IsNotNull(pepo);

            Console.SetIn(new System.IO.StringReader("misho"));
            scoreBoard.AddSkillfulPlayerToBoard(misho, engine.Communicator);
            Assert.AreEqual("misho", misho.Name);

            Console.SetIn(new System.IO.StringReader(""));
            scoreBoard.AddSkillfulPlayerToBoard(stefan, engine.Communicator);
            Assert.AreEqual(null, stefan.Name);

            Console.SetIn(new System.IO.StringReader("carl"));
            scoreBoard.AddSkillfulPlayerToBoard(carl, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("pepo"));
            scoreBoard.AddSkillfulPlayerToBoard(pepo, engine.Communicator);
            Assert.AreEqual(4, scoreBoard.GetLength());
        }
Пример #3
0
 static void Main(string[] args)
 {
     Engine engine = new Engine(GAMEROWS, GAMECOLS);
     engine.RunGame();
     while (engine.currentAction != Engine.CurrentAction.IsNotRunning)
     {
         engine.ReadAction();
     }
 }
Пример #4
0
        public static void Main()
        {
            Console.CursorVisible = false;

            IRenderer renderer = new ConsoleRenderer();

            Engine engine = new Engine(renderer);

            engine.Start();
        }
Пример #5
0
        public void CreateEngineAndExitGame()
        {
            Engine engine = new Engine(5, 10);
            engine.RunGame();
            Console.SetIn(new System.IO.StringReader("exit"));
            engine.ReadAction();
            CurrentAction expected = CurrentAction.IsNotRunning;

            Assert.AreEqual(expected, engine.currentAction);
        }
        public void RenderGameField()
        {
            Engine engine = new Engine(5, 10);
            engine.RunGame();
            Console.SetIn(new System.IO.StringReader("top"));
            engine.ReadAction();
            CurrentAction expected = CurrentAction.PrintingTopBoard;

            Assert.AreEqual(expected, engine.currentAction);

            Mock.Assert(() => engine.Communicator.RenderGameField(engine.Field), Occurs.AtLeastOnce());
        }
Пример #7
0
        public void CreateEngineAndEnterValidCoordinates()
        {
            Engine engine = new Engine(5, 10);
            engine.RunGame();
            Console.SetIn(new System.IO.StringReader("4 4"));
            engine.ReadAction();
            CurrentAction expected = CurrentAction.CheckingCoordinates;
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("4 8"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("4 1"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);

            Console.SetIn(new System.IO.StringReader("4 0"));
            engine.ReadAction();
            Assert.AreEqual(expected, engine.currentAction);
        }
        public void AddPlayersToScoreBoardAndSort()
        {
            Engine engine = new Engine(5, 10);
            ScoreBoard scoreBoard = new ScoreBoard();
            Assert.IsNotNull(scoreBoard);

            Player misho = new Player(20, "misho");
            Assert.IsNotNull(misho);

            Player noNamePlayer = new Player();
            Assert.IsNotNull(noNamePlayer);

            Player carl = new Player(1, "Carl");
            Assert.IsNotNull(carl);

            Player pepo = new Player(5, "Pepito");
            Assert.IsNotNull(pepo);

            Console.SetIn(new System.IO.StringReader("misho"));
            scoreBoard.AddSkillfulPlayerToBoard(misho, engine.Communicator);
            Assert.AreEqual("misho", misho.Name);

            Console.SetIn(new System.IO.StringReader(""));
            scoreBoard.AddSkillfulPlayerToBoard(noNamePlayer, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("Carl"));
            scoreBoard.AddSkillfulPlayerToBoard(carl, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("Pepito"));
            scoreBoard.AddSkillfulPlayerToBoard(pepo, engine.Communicator);

            Assert.AreEqual(4, scoreBoard.GetLength());
            scoreBoard.SortWinnerBoard();

            Assert.AreEqual(noNamePlayer.Name, scoreBoard[0].Name);
            Assert.AreEqual(carl.Name, scoreBoard[1].Name);
            Assert.AreEqual(pepo.Name, scoreBoard[2].Name);
            Assert.AreEqual(misho.Name, scoreBoard[3].Name);
        }
Пример #9
0
 public void CreateEngineAndFinishTheGame()
 {
     Engine engine = new Engine(5, 10);
     engine.RunGame();
     for (int i = 0; i < 11; i++)
     {
         Console.SetIn(new System.IO.StringReader("4 4"));
         engine.ReadAction();
     }
     CurrentAction expected = CurrentAction.IsWaitingForValidInput;
     Assert.AreEqual(expected, engine.currentAction);
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 11; j++)
         {
             Console.SetIn(new System.IO.StringReader(i + " " + j));
             engine.ReadAction();
             if (engine.currentAction == CurrentAction.FinishedGame)
             {
                 break;
             }
         }
     }
     expected = CurrentAction.FinishedGame;
     Assert.AreEqual(expected, engine.currentAction);
 }
Пример #10
0
        public void CreateEngineAndShowTopBoardWithOnePlayer()
        {
            Engine engine = new Engine(5, 10);
            engine.RunGame();

            Player pepo = new Player(5, "Pepito");
            Assert.IsNotNull(pepo);

            Console.SetIn(new System.IO.StringReader("Pepito"));

            engine.ScoreBoard.AddSkillfulPlayerToBoard(pepo, engine.Communicator);
            Console.SetIn(new System.IO.StringReader("top"));
            engine.ReadAction();
            CurrentAction expected = CurrentAction.PrintingTopBoard;
            Assert.AreEqual(expected, engine.currentAction);
            int scoreBoardPlayers = engine.ScoreBoard.GetLength();
            Assert.AreEqual(1, scoreBoardPlayers);
        }
Пример #11
0
 public void CreateEngineAndShowTopBoard()
 {
     Engine engine = new Engine(5, 10);
     engine.RunGame();
     Console.SetIn(new System.IO.StringReader("top"));
     engine.ReadAction();
     CurrentAction expected = CurrentAction.PrintingTopBoard;
     Assert.AreEqual(expected, engine.currentAction);
 }
Пример #12
0
 public void CreateEngineAndRunGame()
 {
     Engine engine = new Engine(5, 10);
     engine.RunGame();
     CurrentAction expected = CurrentAction.IsRunning;
     Assert.AreEqual(expected, engine.currentAction);
 }
        public void AddPlayerToScoreBoard()
        {
            Engine engine = new Engine(5, 10);
            ScoreBoard scoreBoard = new ScoreBoard();
            Assert.IsNotNull(scoreBoard);

            Player misho = new Player(0, "misho");
            Assert.IsNotNull(misho);

            Console.SetIn(new System.IO.StringReader("misho"));
            scoreBoard.AddSkillfulPlayerToBoard(misho, engine.Communicator);
            Assert.AreEqual("misho", misho.Name);
            Assert.AreEqual(1, scoreBoard.GetLength());
        }
        public void ReAddSkillfulPlayerAndSort()
        {
            Engine engine = new Engine(5, 10);
            ScoreBoard scoreBoard = new ScoreBoard();
            Assert.IsNotNull(scoreBoard);

            Player noNamePlayer = new Player(0, "");
            Assert.IsNotNull(noNamePlayer);

            Player carl = new Player(0, "carl");
            Assert.IsNotNull(carl);
            for (int i = 0; i < 3; i++)
            {
                carl.UpdateMovesAmmount();
            }

            Player pepo = new Player(0, "pepo");
            Assert.IsNotNull(pepo);
            for (int i = 0; i < 15; i++)
            {
                pepo.UpdateMovesAmmount();
            }

            Player stefi = new Player(0, "stefi");
            Assert.IsNotNull(stefi);
            for (int i = 0; i < 20; i++)
            {
                stefi.UpdateMovesAmmount();
            }

            Player misho = new Player(0, "misho");
            Assert.IsNotNull(misho);
            for (int i = 0; i < 30; i++)
            {
                misho.UpdateMovesAmmount();
            }

            Player bob = new Player(0, "bob");
            Assert.IsNotNull(bob);
            for (int i = 0; i < 35; i++)
            {
                bob.UpdateMovesAmmount();
            }

            Console.SetIn(new System.IO.StringReader("misho"));
            scoreBoard.AddSkillfulPlayerToBoard(misho, engine.Communicator);
            Assert.AreEqual("misho", misho.Name);

            Console.SetIn(new System.IO.StringReader(""));
            scoreBoard.AddSkillfulPlayerToBoard(noNamePlayer, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("carl"));
            scoreBoard.AddSkillfulPlayerToBoard(carl, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("pepo"));
            scoreBoard.AddSkillfulPlayerToBoard(pepo, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("stefi"));
            scoreBoard.AddSkillfulPlayerToBoard(stefi, engine.Communicator);

            Console.SetIn(new System.IO.StringReader("bob"));
            scoreBoard.AddSkillfulPlayerToBoard(bob, engine.Communicator);

            Assert.AreEqual(6, scoreBoard.GetLength());
            scoreBoard.SortWinnerBoard();

            Assert.AreEqual(null, scoreBoard[0].Name);
            Assert.AreEqual(carl.Name, scoreBoard[1].Name);
            Assert.AreEqual(pepo.Name, scoreBoard[2].Name);
            Assert.AreEqual(stefi.Name, scoreBoard[3].Name);
            Assert.AreEqual(misho.Name, scoreBoard[4].Name);
            Assert.AreEqual(bob.Name, scoreBoard[5].Name);
            for (int i = 0; i < 6; i++)
            {
                misho.UpdateMovesAmmount();
            }

            Console.SetIn(new System.IO.StringReader(""));
            scoreBoard.AddSkillfulPlayerToBoard(misho, engine.Communicator);
            Assert.AreEqual(7, scoreBoard.GetLength());
            scoreBoard.SortWinnerBoard();

            Assert.AreEqual(null, scoreBoard[0].Name);
            Assert.AreEqual(carl.Name, scoreBoard[1].Name);
            Assert.AreEqual(pepo.Name, scoreBoard[2].Name);
            Assert.AreEqual(stefi.Name, scoreBoard[3].Name);
            Assert.AreEqual(misho.Name, scoreBoard[4].Name);
            Assert.AreEqual(bob.Name, scoreBoard[5].Name);
            Assert.AreEqual(null, scoreBoard[6].Name);
        }