private static void SimulateBomb(CharacterState character, List <CharacterState> killedCharacters) { BombState bomb = character.Bomb; bomb.RemainingFuze -= TIME_PER_TURN; if (bomb.RemainingFuze <= 0) { int x = bomb.Position.x; int y = bomb.Position.y; // Center ExplodeTile(x, y, killedCharacters); // Right for (int i = 1; i < bomb.Radius + 1; i++) { if (_state.GetTerrainTypeAtPos(x + i, y) == TerrainType.Wall) { break; } ExplodeTile(x + i, y, killedCharacters); } // Left for (int i = 1; i < bomb.Radius + 1; i++) { if (_state.GetTerrainTypeAtPos(x - i, y) == TerrainType.Wall) { break; } ExplodeTile(x - i, y, killedCharacters); } // Top for (int i = 1; i < bomb.Radius + 1; i++) { if (_state.GetTerrainTypeAtPos(x, y + i) == TerrainType.Wall) { break; } ExplodeTile(x, y + i, killedCharacters); } // Bottom for (int i = 1; i < bomb.Radius + 1; i++) { if (_state.GetTerrainTypeAtPos(x, y - i) == TerrainType.Wall) { break; } ExplodeTile(x, y - i, killedCharacters); } character.Bomb = null; } }
public GameState(CharacterScript self) { MapScript originalMap = GameManagerScript.Instance.Map; Map = new TerrainType[originalMap.Width, originalMap.Height]; for (int y = 0; y < originalMap.Height; y++) { for (int x = 0; x < originalMap.Width; x++) { Map[x, y] = originalMap.GetTerrainTypeAtPos(x, y); } } List <CharacterScript> originalCharacters = GameManagerScript.Instance.Characters; Characters = new List <CharacterState>(); for (int i = 0; i < originalCharacters.Count; i++) { CharacterScript original = originalCharacters[i]; BombState bomb = null; if (!original.Bomb.IsReady) { bomb = new BombState( original.Bomb.RemainingFuze, original.Bomb.Radius, original.Bomb.Position ); } CharacterState character = new CharacterState(original.Position, original.BombFuze, original.BombRadius, bomb); Characters.Add(character); if (original == self) { Self = character; } } Dictionary <Vector2Int, IItem> originalBonuses = GameManagerScript.Instance.Map.Items; Bonuses = new Dictionary <Vector2Int, BonusType>(); foreach (KeyValuePair <Vector2Int, IItem> pair in originalBonuses) { BonusType type; switch (pair.Value) { case FuzeItemScript _: type = BonusType.Fuze; break; case RadiusItemScript _: type = BonusType.Radius; break; default: throw new InvalidOperationException($"Unknown item type: {pair.Value.GetType()}"); } Bonuses.Add(pair.Key, type); } Turn = 0; }