Example #1
0
        public void RenderMapCheckCorrectlyElementsTest()
        {
            FakeMap map = new FakeMap(4, 3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();
            int count    = 0;
            int allCount = 0;

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    allCount++;
                    if (map.Hit(i, j) is HitResult)
                    {
                        count++;
                    }
                }
            }

            Assert.IsTrue(allCount == 12 && count == 9, "The map is rendered fail");
        }
Example #2
0
        public void UserInterfaceCommunicationTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player           = new Player(map);
            int    hitResult        = 0;
            int    hitAndSinkResult = 0;
            Game   game             = new Game(player, fakeUserInterface);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                    if (fakeUserInterface.Reuslt is HitResult)
                    {
                        hitResult++;
                    }

                    if (fakeUserInterface.Reuslt is HitAndSinksResult)
                    {
                        hitAndSinkResult++;
                    }
                }
            }

            Assert.IsTrue(hitResult == 9 && hitAndSinkResult == 3, "The User interface got wrong information");
        }
Example #3
0
        public void CheckRenderMapOnUserInterfaceConnectionWithoutRenderTest()
        {
            FakeUserInterface fake = new FakeUserInterface();
            Game game = new Game(null, fake);

            game.NextTurn(0, 0);
            Assert.IsFalse(fake.RenderMapDone, "The Render map has worked");
        }
Example #4
0
        public void CheckErrorUserInterfaceConnectionTest()
        {
            FakeUserInterface fake = new FakeUserInterface();
            Game game = new Game(null, fake);

            game.NextTurn(0, 0);
            Assert.IsTrue(fake.ShowErrorDone, "The error was not displayed");
        }
Example #5
0
        public void CheckRenderMapWithoutPrepareTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();
            Assert.IsTrue(fakeUserInterface.RenderMapDone && fakeUserInterface.PrepareGameDone == false, "Prepare map is not working correctly");
        }
Example #6
0
        public void CheckRenderMapOnUserInterfaceConnectionWhenEverythingIsOKTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();
            Assert.IsTrue(fakeUserInterface.RenderMapDone, "The Render map has not worked");
        }
Example #7
0
        public void NotYetWinnerTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);
            Game   game   = new Game(player, fakeUserInterface);

            Assert.IsFalse(fakeUserInterface.Winner, "The player is winner");
        }
Example #8
0
        public void CheckRenderMapOnUserInterfaceAfterHitAndRenderTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game  = new Game(player, fakeUserInterface);
            int  point = 0;

            game.NextTurn(point, point);
            game.RenderMap();
            Assert.AreEqual(Water.DEFAULT_WATER_FILENAME, map.Fields[point, point].GetIconToElement(), "The icon of object is incorrect rendered");
        }
Example #9
0
        public void CheckErrorUserInterfaceConnectionWhenEverythingIsOKTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.NextTurn(0, 0);
            Assert.IsFalse(fakeUserInterface.ShowErrorDone, "The error was displayed");
        }
Example #10
0
        public void WinnerTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);
            Game   game   = new Game(player, fakeUserInterface);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }
            Assert.IsTrue(fakeUserInterface.Winner, "The player is not winner");
        }
Example #11
0
        public void CheckStepsPlayerTest()
        {
            FakeMap map = new FakeMap(1, 3, new List <LiveElement>()
            {
                new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }

            Assert.IsTrue(fakeUserInterface.CurrenctScore == 3 && fakeUserInterface.YourRecord == 3, "Score and The best score is not correctly");
        }
Example #12
0
        public void TheBestScoreOfPlayerTest()
        {
            FakeMap map = new FakeMap(4, 3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }

            Assert.IsTrue(player.BestSteps > 0, "The best score of player is wrong");
        }