示例#1
0
文件: Map.cs 项目: MatasGos/BMAN
 public Map(int xSize, int ySize)
 {
     this.xSize = xSize;
     this.ySize = ySize;
     units      = new Unit[xSize, ySize];
     explosions = new Explosive[xSize, ySize];
     mapFacade  = new MapFacade(xSize, ySize, units, explosions);
 }
示例#2
0
 public void Visit(Explosive explosive)
 {
     if (explosive.explosionPower < 5)
     {
         explosive.explosionPower = 5;
     }
     if (explosive is Bomb)
     {
         Bomb b = (Bomb)explosive;
         b.detonationTime = 0.0;
     }
     else if (explosive is SuperBomb)
     {
         SuperBomb sb = (SuperBomb)explosive;
         sb.detonationTime = 0.0;
     }
 }
示例#3
0
 public void Visit(Explosive explosive)
 {
 }
示例#4
0
        public void PlaceExplosive(Player player, double placeTime)
        {
            if (player.action == "")
            {
                return;
            }

            int[] playerCenter = getCenterPlayer(new int[] { player.x, player.y });
            int[] playerTile   = getTile(playerCenter[0], playerCenter[1]);

            ExplosiveAbstractFactory factory;
            Explosive toPlace = null;

            string command    = player.action;
            bool   placeSuper = false;

            if (command[command.Length - 1] == 'S')
            {
                placeSuper = true;
                command    = command.Remove(command.Length - 1);
            }

            if (units[playerTile[0], playerTile[1]] == null)
            {
                if (placeSuper && player.hasSuperbombs)
                {
                    factory = new SuperExplosiveConcreteFactory();
                }
                else
                {
                    factory = new RegularExplosiveConcreteFactory();
                }

                switch (command)
                {
                case "placeBomb":
                    toPlace = factory.CreateBomb(playerTile[0], playerTile[1], player.explosionPower, placeTime, player);
                    break;

                case "placeMine":
                    toPlace = factory.CreateMine(playerTile[0], playerTile[1], player);
                    break;

                default:
                    throw new Exception();
                }
                bool canPlace = true;
                switch (toPlace)
                {
                case Bomb x:
                    if (player.bombCount <= 0)
                    {
                        canPlace = false;
                    }
                    else
                    {
                        player.bombCount--;
                    }
                    break;

                case SuperBomb x:
                    if (player.superBombCount <= 0)
                    {
                        canPlace = false;
                    }
                    else
                    {
                        player.superBombCount--;
                    }
                    break;

                case Mine x:
                    if (player.mineCount <= 0)
                    {
                        canPlace = false;
                    }
                    else
                    {
                        player.mineCount--;
                    }
                    break;

                case SuperMine x:
                    if (player.superMineCount <= 0)
                    {
                        canPlace = false;
                    }
                    else
                    {
                        player.superMineCount--;
                    }
                    break;

                default:
                    break;
                }
                if (canPlace)
                {
                    units[playerTile[0], playerTile[1]] = toPlace;
                }
            }

            player.action = "";
        }