public void UpdateExplosives(double time) { for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { ExplosiveAbstractFactory factory; if (explosions[x, y] is Explosion) { Explosion explosion = (Explosion)explosions[x, y]; if (explosion.removalTime < time) { explosions[x, y] = null; } } else if (explosions[x, y] is SuperExplosion) { SuperExplosion explosion = (SuperExplosion)explosions[x, y]; if (explosion.removalTime < time) { explosions[x, y] = null; } } if (units[x, y] is Bomb) { factory = new RegularExplosiveConcreteFactory(); Bomb bomb = (Bomb)units[x, y]; if (bomb.detonationTime < time) { bomb.GetOwner().bombCount++; units[x, y] = null; PlaceRegularExplosion(x, y, bomb.explosionPower, time, factory, bomb.GetOwner()); } } else if (units[x, y] is SuperBomb) { factory = new SuperExplosiveConcreteFactory(); SuperBomb bomb = (SuperBomb)units[x, y]; if (bomb.detonationTime < time) { units[x, y] = null; PlaceSuperExplosion(x, y, bomb.explosionPower, time, factory, bomb.GetOwner()); } } } } }
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 = ""; }