コード例 #1
0
ファイル: Player.cs プロジェクト: gGvidas/bomberman
 public Player(string id, int x, int y)
 {
     Id     = id;
     this.x = x;
     this.y = y;
     this.destroyedEntities = new CompositeDirectory();
 }
コード例 #2
0
ファイル: World.cs プロジェクト: gGvidas/bomberman
        public void Explode(int x, int y)
        {
            if (Map.Objects[x][y].bomb == null)
            {
                return;
            }
            CompositeDirectory destroyedEntities = new CompositeDirectory();

            int radius = Map.Objects[x][y].bomb.explosionRadius(2);

            Map.Objects[x][y].destroy();

            var wallFactory = new WallFactory();

            bool up = false, down = false, left = false, right = false;

            for (int i = 1; i <= radius; i++)
            {
                if (x + i < numSquaresX && !(Map.Objects[x + i][y].entity is IndestructableWall) && !(Map.Objects[x + i][y].entity is Fire) && !right)
                {
                    if (Map.Objects[x][y].bomb is FireBomb)
                    {
                        Map.Objects[x + i][y].entity = new Fire(x + i, y);
                    }
                    else if (Map.Objects[x][y].bomb is IceBomb)
                    {
                        if (!(Map.Objects[x + 1][y].entity is DestructableWall))
                        {
                            Map.Objects[x + i][y].entity = wallFactory.CreateWall(4);
                        }
                        else
                        {
                            right = true;
                        }
                    }
                    else
                    {
                        DestructionTemplate destroyedObject = Map.Objects[x + i][y].destroy();
                        if (destroyedObject != null)
                        {
                            destroyedEntities.add(destroyedObject);
                        }
                    }
                }
                else
                {
                    right = true;
                }
                if (x - i >= 0 && !(Map.Objects[x - i][y].entity is IndestructableWall) && !(Map.Objects[x - i][y].entity is Fire) && !left)
                {
                    if (Map.Objects[x][y].bomb is FireBomb)
                    {
                        Map.Objects[x - i][y].entity = new Fire(x - i, y);
                    }
                    else if (Map.Objects[x][y].bomb is IceBomb)
                    {
                        if (!(Map.Objects[x - 1][y].entity is DestructableWall))
                        {
                            Map.Objects[x - i][y].entity = wallFactory.CreateWall(4);
                        }
                        else
                        {
                            left = true;
                        }
                    }
                    else
                    {
                        DestructionTemplate destroyedObject = Map.Objects[x - i][y].destroy();
                        if (destroyedObject != null)
                        {
                            destroyedEntities.add(destroyedObject);
                        }
                    }
                }
                else
                {
                    left = true;
                }
                if (y + i < numSquaresX && !(Map.Objects[x][y + i].entity is IndestructableWall) && !(Map.Objects[x][y + i].entity is Fire) && !up)
                {
                    if (Map.Objects[x][y].bomb is FireBomb)
                    {
                        Map.Objects[x][y + i].entity = new Fire(x, y - i);
                    }
                    else if (Map.Objects[x][y].bomb is IceBomb)
                    {
                        if (!(Map.Objects[x][y + i].entity is DestructableWall))
                        {
                            Map.Objects[x][y + i].entity = wallFactory.CreateWall(4);
                        }
                        else
                        {
                            down = true;
                        }
                    }
                    else
                    {
                        DestructionTemplate destroyedObject = Map.Objects[x][y + i].destroy();
                        if (destroyedObject != null)
                        {
                            destroyedEntities.add(destroyedObject);
                        }
                    }
                }
                else
                {
                    down = true;
                }
                if (y - i >= 0 && !(Map.Objects[x][y - i].entity is IndestructableWall) && !(Map.Objects[x][y - i].entity is Fire) && !down)
                {
                    if (Map.Objects[x][y].bomb is FireBomb)
                    {
                        Map.Objects[x][y - i].entity = new Fire(x, y - i);
                    }
                    else if (Map.Objects[x][y].bomb is IceBomb)
                    {
                        if (!(Map.Objects[x][y - i].entity is DestructableWall))
                        {
                            Map.Objects[x][y - i].entity = wallFactory.CreateWall(4);
                        }
                        else
                        {
                            up = true;
                        }
                    }
                    else
                    {
                        DestructionTemplate destroyedObject = Map.Objects[x][y - i].destroy();
                        if (destroyedObject != null)
                        {
                            destroyedEntities.add(destroyedObject);
                        }
                    }
                }
                else
                {
                    up = true;
                }
            }
            Player player = GetPlayer(Map.Objects[x][y].bomb.playerId);

            if (player != null)
            {
                player.destroyedEntities.add(destroyedEntities);
            }
            Map.Objects[x][y].bomb = null;
        }