private void MovePlayerToLocation(Player player, int x, int y)
        {
            while (player.PlayerEntity.Location.X != x || player.PlayerEntity.Location.Y != y)
            {
                var processor = new GameRoundProcessor(0, _gameMap, _logger);

                if (player.PlayerEntity.Location.X > x)
                {
                    processor.AddPlayerCommand(player, new MovementCommand(MovementCommand.Direction.Left));
                    processor.ProcessRound();
                    continue;
                }
                if (player.PlayerEntity.Location.X < x)
                {
                    processor.AddPlayerCommand(player, new MovementCommand(MovementCommand.Direction.Right));
                    processor.ProcessRound();
                    continue;
                }
                if (player.PlayerEntity.Location.Y > y)
                {
                    processor.AddPlayerCommand(player, new MovementCommand(MovementCommand.Direction.Up));
                    processor.ProcessRound();
                    continue;
                }
                if (player.PlayerEntity.Location.Y < y)
                {
                    processor.AddPlayerCommand(player, new MovementCommand(MovementCommand.Direction.Down));
                    processor.ProcessRound();
                    continue;
                }
            }
        }
예제 #2
0
        public void TwoBombsSameEntity()
        {
            /* #######
             * #     #
             * #     #
             * # a+b #
             * #     #
             * #     #
             * #######
             */

            var block = _gameMap.GetBlockAtLocation(3, 3);

            block.SetEntity(new DestructibleWallEntity());

            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];


            block = _gameMap.GetBlockAtLocation(player1.PlayerEntity.Location.X, player1.PlayerEntity.Location.Y);
            block.SetEntity(null);
            block = _gameMap.GetBlockAtLocation(player2.PlayerEntity.Location.X, player2.PlayerEntity.Location.Y);
            block.SetEntity(null);

            block = _gameMap.GetBlockAtLocation(2, 3);
            block.SetEntity(player1.PlayerEntity);
            block = _gameMap.GetBlockAtLocation(4, 3);
            block.SetEntity(player2.PlayerEntity);

            processor.AddPlayerCommand(player1, new PlaceBombCommand());
            processor.AddPlayerCommand(player2, new PlaceBombCommand());
            processor.ProcessRound();

            block = _gameMap.GetBlockAtLocation(player1.PlayerEntity.Location.X, player1.PlayerEntity.Location.Y);
            block.SetEntity(null);
            block = _gameMap.GetBlockAtLocation(player2.PlayerEntity.Location.X, player2.PlayerEntity.Location.Y);
            block.SetEntity(null);

            block = _gameMap.GetBlockAtLocation(3, 1);
            block.SetEntity(player1.PlayerEntity);
            block = _gameMap.GetBlockAtLocation(2, 1);
            block.SetEntity(player2.PlayerEntity);

            var bomb = _gameMap.GetPlayerBombs(player1.PlayerEntity).FirstOrDefault();

            while (bomb != null && bomb.BombTimer > 0)
            {
                processor = new GameRoundProcessor(0, _gameMap, _logger);
                processor.ProcessRound();
            }

            Assert.AreEqual(player1.PlayerEntity.Points - player1.PlayerEntity.MapCoveragePoints, 10, "Player 1 should have recieved points for destroying wall entity");
            Assert.AreEqual(player2.PlayerEntity.Points - player2.PlayerEntity.MapCoveragePoints, 10, "Player 2 should have recieved points for destroying wall entity");
        }
        public void ChainBombPointAllocationForumScenario4()
        {
            // 4  1
            //
            // +  1
            //
            // 20 points.

            var player1 = _players[0];

            player1.PlayerEntity.BombRadius = 2;

            var player2 = _players[1];

            player2.PlayerEntity.BombRadius = 2;
            player2.PlayerEntity.BombBag    = 2;

            _gameMap.GetBlockAtLocation(1, 3).SetEntity(new DestructibleWallEntity());

            MovePlayerToLocation(player2, 3, 1);

            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            processor.AddPlayerCommand(player1, new PlaceBombCommand(10));
            processor.AddPlayerCommand(player2, new PlaceBombCommand(10));
            processor.ProcessRound();

            var bomb = _gameMap.GetPlayerBombs(player1.PlayerEntity).FirstOrDefault();

            MovePlayerToLocation(player1, 2, 2);
            MovePlayerToLocation(player2, 3, 3);

            processor = new GameRoundProcessor(1, _gameMap, _logger);
            processor.AddPlayerCommand(player2, new PlaceBombCommand(10));
            processor.ProcessRound();

            MovePlayerToLocation(player2, 4, 4);

            while (bomb != null && !bomb.IsExploding)
            {
                processor = new GameRoundProcessor(1, _gameMap, _logger);
                processor.ProcessRound();
            }
            //Process another round to assign points
            processor = new GameRoundProcessor(1, _gameMap, _logger);
            processor.ProcessRound();

            Assert.AreEqual(20, player1.PlayerEntity.Points - player1.PlayerEntity.MapCoveragePoints, "Player 1 should have received points for destroying wall");
            Assert.AreEqual(20, player2.PlayerEntity.Points - player2.PlayerEntity.MapCoveragePoints, "Player 2 should have received points for destroying wall");
        }
        public void TestPlayerMoveIntoBombBlast()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            MovePlayerToLocation(player1, 4, 4);

            processor.AddPlayerCommand(player2, new PlaceBombCommand());
            processor.ProcessRound();

            var bomb = _gameMap.GetPlayerBombs(player2.PlayerEntity).First();

            while (bomb.BombTimer > 1)
            {
                processor = new GameRoundProcessor(1, _gameMap, _logger);
                processor.ProcessRound();
            }

            processor = new GameRoundProcessor(1, _gameMap, _logger);
            processor.AddPlayerCommand(player1, new MovementCommand(MovementCommand.Direction.Down));
            processor.ProcessRound();

            Assert.IsTrue(player1.PlayerEntity.Killed, "Player 1 should have been killed by bomb blast");
            Assert.IsTrue(player2.PlayerEntity.Killed, "Player 2 should have been killed by bomb blast");
        }
        public void TestBombChaining()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            player1.PlayerEntity.BombRadius = 4;

            MovePlayerToLocation(player1, 3, 3);
            MovePlayerToLocation(player2, 5, 3);

            processor.AddPlayerCommand(player1, new PlaceBombCommand());
            processor.ProcessRound();

            processor = new GameRoundProcessor(1, _gameMap, _logger);
            processor.ProcessRound();

            processor = new GameRoundProcessor(1, _gameMap, _logger);
            processor.AddPlayerCommand(player2, new PlaceBombCommand());
            processor.ProcessRound();

            var bomb  = _gameMap.GetPlayerBombs(player1.PlayerEntity).First();
            var bomb2 = _gameMap.GetPlayerBombs(player2.PlayerEntity).First();

            while (bomb.BombTimer > 0)
            {
                processor = new GameRoundProcessor(1, _gameMap, _logger);
                processor.ProcessRound();
            }

            Assert.True(bomb.IsExploding, "Player 1 bomb should be exploding");
            Assert.True(bomb2.IsExploding, "Player 2 bomb should be exploding");
        }
        public void TestPlayersBumbIntoEachOther()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            MovePlayerToLocation(player1, 3, 3);
            MovePlayerToLocation(player2, 5, 3);

            processor.AddPlayerCommand(player1, new MovementCommand(MovementCommand.Direction.Right));
            processor.AddPlayerCommand(player2, new MovementCommand(MovementCommand.Direction.Left));

            Assert.True(player1.PlayerEntity.Location.X == 3, "Player 1 should not have moved");
            Assert.True(player2.PlayerEntity.Location.X == 5, "Player 2 should not have moved");
        }
예제 #7
0
        public void TestPlayersAdjacentPlayersMovingTowardsEachOther()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            MovePlayerToLocation(player1, 1, 1);
            MovePlayerToLocation(player2, 2, 1);

            processor.AddPlayerCommand(player1, new MovementCommand(MovementCommand.Direction.Right));
            processor.AddPlayerCommand(player2, new MovementCommand(MovementCommand.Direction.Left));

            processor.ProcessRound();

            Assert.True(player1.PlayerEntity.Location.X == 1, "Player 1 should not have moved");
            Assert.True(player2.PlayerEntity.Location.X == 2, "Player 2 should not have moved");
        }
        public void TestAddPlayerCommand()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            processor.AddPlayerCommand(player1, new DoNothingCommand());
            processor.AddPlayerCommand(player1, new PlaceBombCommand());
            Assert.AreEqual(1, processor.CountCommandsRecieved(), "Game processor should not allow multiple commands for the same player");

            player2.PlayerEntity.Killed = true;
            processor.AddPlayerCommand(player2, new PlaceBombCommand());
            Assert.AreEqual(1, processor.CountCommandsRecieved(), "Game processor should not allow killed players to add commands");
            player2.PlayerEntity.Killed = false;

            processor.AddPlayerCommand(player2, new DoNothingCommand());
            Assert.AreEqual(2, processor.CountCommandsRecieved(), "Game processor did not add all of the commands expected");
        }
        public void TwoBombsPersonSuicide()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            var block = _gameMap.GetBlockAtLocation(player1.PlayerEntity.Location.X, player1.PlayerEntity.Location.Y);

            block.SetEntity(null);
            block = _gameMap.GetBlockAtLocation(player2.PlayerEntity.Location.X, player2.PlayerEntity.Location.Y);
            block.SetEntity(null);

            block = _gameMap.GetBlockAtLocation(2, 3);
            block.SetEntity(player1.PlayerEntity);
            block = _gameMap.GetBlockAtLocation(4, 3);
            block.SetEntity(player2.PlayerEntity);

            processor.AddPlayerCommand(player1, new PlaceBombCommand());
            processor.AddPlayerCommand(player2, new PlaceBombCommand());
            processor.ProcessRound();

            block = _gameMap.GetBlockAtLocation(player1.PlayerEntity.Location.X, player1.PlayerEntity.Location.Y);
            block.SetEntity(null);
            block = _gameMap.GetBlockAtLocation(player2.PlayerEntity.Location.X, player2.PlayerEntity.Location.Y);
            block.SetEntity(null);

            block = _gameMap.GetBlockAtLocation(3, 1);
            block.SetEntity(player1.PlayerEntity);
            block = _gameMap.GetBlockAtLocation(3, 3);
            block.SetEntity(player2.PlayerEntity);

            var bomb = _gameMap.GetPlayerBombs(player1.PlayerEntity).FirstOrDefault();

            while (bomb != null && bomb.BombTimer > 0)
            {
                processor = new GameRoundProcessor(0, _gameMap, _logger);
                processor.ProcessRound();
            }

            Assert.AreEqual(player1.PlayerEntity.Points, 112, "Player 1 should have recieved points for kiling player 2");
            Assert.AreEqual(player2.PlayerEntity.Points, -88, "Player 2 should have lost points for killing itself");
        }
예제 #10
0
        public void TestPlayerMovingIntoWall()
        {
            var processor = new GameRoundProcessor(1, _gameMap, _logger);

            var player1 = _players[0];
            var player2 = _players[1];

            MovePlayerToLocation(player1, 1, 1);
            MovePlayerToLocation(player2, 2, 1);

            _gameMap.GetBlockAtLocation(3, 1).SetEntity(new IndestructibleWallEntity());

            processor.AddPlayerCommand(player1, new MovementCommand(MovementCommand.Direction.Right));
            processor.AddPlayerCommand(player2, new MovementCommand(MovementCommand.Direction.Right));

            processor.ProcessRound();

            Assert.True(player1.PlayerEntity.Location.X == 1, "Player 1 should not have moved");
            Assert.True(player2.PlayerEntity.Location.X == 2, "Player 2 should not have moved");
        }