Beispiel #1
0
        public void R21_4_GAME_BALL_ENEMY_AMONG_US()
        {
            Game  game      = FactoryTest.getGameWithScenario(new EnemyAmongUs());
            int   nbBallP1  = 0;
            int   nbBallP2  = 0;
            int   sizeBoard = Properties.DEFAULT_SIZE_BOARD;
            Board board     = game.Board;

            for (int i = 0; i < sizeBoard; i++)
            {
                for (int j = 0; j < sizeBoard; j++)
                {
                    if (board.getTile(i, j).hasPiece() && board.getTile(i, j).Piece.hasBall())
                    {
                        if (board.getTile(i, j).Piece.Player.Equals(game.P1))
                        {
                            nbBallP1++;
                        }
                        if (board.getTile(i, j).Piece.Player.Equals(game.P2))
                        {
                            nbBallP2++;
                        }
                    }
                }
            }
            Assert.AreEqual(nbBallP1, nbBallP2);
            Assert.AreEqual(1, nbBallP2);
        }
Beispiel #2
0
        public void R21_15_GAMEPLAY_TURN_MANUALLY()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();


            if (game.PlayerWhoPlay.Equals(game.P1))
            {
                game.Board.getTile(0, 0).click(game.P1);
                game.Board.getTile(1, 0).click(game.P1);

                game.PlayerWhoPlay.endTurn();

                Assert.AreNotEqual(game.PlayerWhoPlay, game.P1);
            }
            else
            {
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 1, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(game.P2);

                game.PlayerWhoPlay.endTurn();

                Assert.AreNotEqual(game.PlayerWhoPlay, game.P2);
            }
        }
Beispiel #3
0
        public void R21_3_GAME_PIECES_NUMBER_OF_PIECES_BALL_RANDOM()
        {
            Game  game      = FactoryTest.getGameWithScenario(new BallRandom());
            int   nbPieceP1 = 0;
            int   nbPieceP2 = 0;
            int   sizeBoard = Properties.DEFAULT_SIZE_BOARD;
            Board board     = game.Board;

            for (int i = 0; i < sizeBoard; i++)
            {
                for (int j = 0; j < sizeBoard; j++)
                {
                    if (board.getTile(i, j).hasPiece())
                    {
                        if (board.getTile(i, j).Piece.Player.Equals(game.P1))
                        {
                            nbPieceP1++;
                        }
                        if (board.getTile(i, j).Piece.Player.Equals(game.P2))
                        {
                            nbPieceP2++;
                        }
                    }
                }
            }
            Assert.AreEqual(nbPieceP1, nbPieceP2);
            Assert.AreEqual(nbPieceP1, sizeBoard);
        }
Beispiel #4
0
        public void R22_1_SCENARIO_STANDARD()
        {
            Game  game      = FactoryTest.getGameWithScenario(new Standart());
            int   sizeBoard = Properties.DEFAULT_SIZE_BOARD;
            Board board     = game.Board;

            for (int i = 0; i < sizeBoard; i++)
            {
                Assert.IsTrue(board.getTile(0, i).hasPiece());
                Assert.IsTrue(board.getTile(0, i).Piece.Player.Equals(game.P1));
                if (i == (sizeBoard / 2))
                {
                    Assert.IsTrue(board.getTile(0, i).Piece.Ball.Player.Equals(game.P1));
                    Assert.IsTrue(board.getTile(0, i).Piece.hasBall());
                }
            }
            for (int i = 0; i < sizeBoard; i++)
            {
                Assert.IsTrue(board.getTile(sizeBoard - 1, i).hasPiece());
                Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.Player.Equals(game.P2));
                if (i == sizeBoard / 2)
                {
                    Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.Ball.Player.Equals(game.P2));
                    Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.hasBall());
                }
            }
        }
Beispiel #5
0
        public void R21_6_GAMEPLAY_TURN_LESS_3_MOVE_MORE_THAN_1()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();

            Player Iamplaying = game.PlayerWhoPlay;

            if (game.Board.getTile(0, 0).Piece.Player.Equals(Iamplaying))
            {
                game.Board.getTile(0, 0).click(Iamplaying);
                game.Board.getTile(1, 0).click(Iamplaying);

                Iamplaying.endTurn();

                bool res = game.Board.getTile(1, 0).click(Iamplaying);

                Assert.IsFalse(res);
            }
            else
            {
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 1, 0).click(Iamplaying);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(Iamplaying);

                Iamplaying.endTurn();

                bool res = game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(Iamplaying);

                Assert.IsFalse(res);
            }
        }
Beispiel #6
0
        public void R22_2_SCENARIO_BALL_RANDOM()
        {
            Game  game      = FactoryTest.getGameWithScenario(new BallRandom());
            int   sizeBoard = Properties.DEFAULT_SIZE_BOARD;
            Board board     = game.Board;
            bool  ball      = false;

            for (int i = 0; i < sizeBoard; i++)
            {
                Assert.IsTrue(board.getTile(0, i).hasPiece());
                Assert.IsTrue(board.getTile(0, i).Piece.Player.Equals(game.P1));
                if (board.getTile(0, i).Piece.hasBall())
                {
                    Assert.IsTrue(board.getTile(0, i).Piece.Ball.Player.Equals(game.P1));
                    ball = true;
                }
            }
            Assert.IsTrue(ball);
            ball = false;
            for (int i = 0; i < sizeBoard; i++)
            {
                Assert.IsTrue(board.getTile(sizeBoard - 1, i).hasPiece());
                Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.Player.Equals(game.P2));
                if (board.getTile(sizeBoard - 1, i).Piece.hasBall())
                {
                    Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.Ball.Player.Equals(game.P2));
                    ball = true;
                }
            }
            Assert.IsTrue(ball);
        }
Beispiel #7
0
        public void R24_1_VICTORY_P2()
        {
            Game game = FactoryTest.getGameWithScenario(new Standart());

            Assert.AreEqual(0, game.verifyVictory());
            game.Board.getTile(0, 0).Piece = game.Board.getTile(game.Board.SizeBoard - 1, game.Board.SizeBoard / 2).Piece;
            Assert.AreEqual(2, game.verifyVictory());
        }
Beispiel #8
0
        public void R21_1_GAME_PLAYERS_TWO_PLAYERS_ERROR()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();
        }
Beispiel #9
0
        public void TEST_RESUME_A_GAME()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();


            if (game.PlayerWhoPlay.Equals(game.P1))
            {
                game.Board.getTile(0, 0).click(game.P1);
                game.Board.getTile(1, 0).click(game.P1);

                game.Board.getTile(1, 0).click(game.P1);
                game.Board.getTile(2, 0).click(game.P1);

                game.Board.getTile(2, 0).click(game.P1);
                game.Board.getTile(3, 0).click(game.P1);
            }
            else
            {
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 1, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(game.P2);

                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 3, 0).click(game.P2);

                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 3, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).click(game.P2);
            }


            int idGame = game.Board.MementoManager.getId();

            //Chargement de la partie précédente

            GameBuilder gameBuilderResume = GameBuilder.create();

            Game gameResume = gameBuilderResume.build(idGame);

            Assert.AreEqual(game.P1.Name, gameResume.P1.Name);
            Assert.AreEqual(game.P2.Name, gameResume.P2.Name);

            if (game.P1.NumberTurn == 1)
            {
                Assert.AreEqual(game.Board.getTile(3, 0).hasPiece(), gameResume.Board.getTile(3, 0).hasPiece());
                Assert.IsTrue(gameResume.Board.getTile(3, 0).hasPiece());
                Assert.IsFalse(gameResume.Board.getTile(2, 0).hasPiece());
            }
            else
            {
                Assert.AreEqual(game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).hasPiece(), gameResume.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).hasPiece());
                Assert.IsTrue(gameResume.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).hasPiece());
                Assert.IsFalse(gameResume.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 3, 0).hasPiece());
            }
        }
Beispiel #10
0
        public static Game getRandomGame()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            return(gameBuilder.build());
        }
Beispiel #11
0
        public void R21_5_GAME_COLOUR_HAVE_SAME_COLOR()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();
        }
Beispiel #12
0
        public void R21_1_GAME_PLAYERS_NO_NAME()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, null);
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();
        }
Beispiel #13
0
        public static Game getGameWithScenario(Scenario sce)
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = sce;
            return(gameBuilder.build());
        }
Beispiel #14
0
        public void R21_1_GAME_PLAYERS_WITH_NAME()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();

            Assert.AreEqual("test", game.P1.Name);
        }
Beispiel #15
0
        public void R22_3_SCENARIO_ENEMY_AMONG_US()
        {
            Game  game      = FactoryTest.getGameWithScenario(new EnemyAmongUs());
            int   sizeBoard = Properties.DEFAULT_SIZE_BOARD;
            Board board     = game.Board;

            int nbPieceP1 = 0;
            int nbPieceP2 = 0;

            for (int i = 0; i < sizeBoard; i++)
            {
                if (i == sizeBoard / 2)
                {
                    Assert.IsTrue(board.getTile(0, i).Piece.Ball.Player.Equals(game.P1));
                    nbPieceP1++;
                }
                else if (board.getTile(0, i).Piece.Player.Equals(game.P1))
                {
                    nbPieceP1++;
                }
                else if (board.getTile(0, i).Piece.Player.Equals(game.P2))
                {
                    nbPieceP2++;
                }
            }

            Assert.AreEqual(nbPieceP1, sizeBoard - 2);
            Assert.AreEqual(nbPieceP2, 2);
            nbPieceP1 = 0;
            nbPieceP2 = 0;

            for (int i = 0; i < sizeBoard; i++)
            {
                if (i == sizeBoard / 2)
                {
                    Assert.IsTrue(board.getTile(sizeBoard - 1, i).Piece.Ball.Player.Equals(game.P2));
                    nbPieceP2++;
                }
                else if (board.getTile(sizeBoard - 1, i).Piece.Player.Equals(game.P1))
                {
                    nbPieceP1++;
                }
                else if (board.getTile(sizeBoard - 1, i).Piece.Player.Equals(game.P2))
                {
                    nbPieceP2++;
                }
            }

            Assert.AreEqual(nbPieceP2, sizeBoard - 2);
            Assert.AreEqual(nbPieceP1, 2);
        }
Beispiel #16
0
        public void R21_6_GAMEPLAY_TURN_LESS_1_MOVE()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();

            Player Iamplaying = game.PlayerWhoPlay;

            game.PlayerWhoPlay.endTurn();
            Assert.AreEqual(Iamplaying, game.PlayerWhoPlay);
        }
Beispiel #17
0
        public void R21_1_GAME_PLAYERS_TWO_PLAYERS()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            try
            {
                Game game = gameBuilder.build();
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
Beispiel #18
0
        public void R21_6_GAMEPLAY_TURN_3_MOVE()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();


            if (game.PlayerWhoPlay.Equals(game.P1))
            {
                game.Board.getTile(0, 0).click(game.P1);
                game.Board.getTile(1, 0).click(game.P1);

                game.Board.getTile(1, 0).click(game.P1);
                game.Board.getTile(2, 0).click(game.P1);

                game.Board.getTile(2, 0).click(game.P1);
                game.Board.getTile(3, 0).click(game.P1);

                Assert.AreNotEqual(game.P1, game.PlayerWhoPlay);

                bool res = game.Board.getTile(3, 0).click(game.P1);
                Assert.IsFalse(res);
            }
            else
            {
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 1, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(game.P2);

                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 2, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 3, 0).click(game.P2);

                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 3, 0).click(game.P2);
                game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).click(game.P2);

                Assert.AreNotEqual(game.P2, game.PlayerWhoPlay);

                bool res = game.Board.getTile(Properties.DEFAULT_SIZE_BOARD - 4, 0).click(game.P2);
                Assert.IsFalse(res);
            }
        }
Beispiel #19
0
        public void R21_10_GAMEPLAY_MOVE_PIECE()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();

            Assert.IsNull(game.Board.getTile(1, 0).Piece);
            Assert.IsNotNull(game.Board.getTile(0, 0).Piece);

            game.Board.getTile(0, 0).buildDecision();

            Assert.IsTrue(game.Board.getTile(1, 0).Selected);

            game.Board.getTile(1, 0).buildDecision();

            Assert.IsNull(game.Board.getTile(0, 0).Piece);
            Assert.IsNotNull(game.Board.getTile(1, 0).Piece);
        }
Beispiel #20
0
        public void Test_convertBoardForCpp()
        {
            GameBuilder gameBuilder = GameBuilder.create();

            gameBuilder.Player1  = FactoryTest.getPlayerBuilderHuman(Color.Red, "test");
            gameBuilder.Player2  = FactoryTest.getPlayerBuilderHuman(Color.Blue, "test2");
            gameBuilder.Scenario = new Standart();
            Game game = gameBuilder.build();

            Assert.AreEqual(1, game.P1.NumberPlayer);
            Assert.AreEqual(2, game.P2.NumberPlayer);
            int[] boardCpp = game.Board.convertBoardForCpp();
            for (int line = 0; line < 7; line++)
            {
                for (int column = 0; column < 7; column++)
                {
                    if (line == 0 && column == 3)
                    {
                        Assert.AreEqual(3, boardCpp[line * 7 + column]);
                    }
                    else if (line == 6 && column == 3)
                    {
                        Assert.AreEqual(4, boardCpp[line * 7 + column]);
                    }
                    else if (line == 0)
                    {
                        Assert.AreEqual(1, boardCpp[line * 7 + column]);
                    }
                    else if (line == 6)
                    {
                        Assert.AreEqual(2, boardCpp[line * 7 + column]);
                    }
                    else
                    {
                        Assert.AreEqual(0, boardCpp[line * 7 + column]);
                    }
                }
            }
        }