public Map CopyAndFlip(Map map, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities) { var copy = new Map(map); // Copy all entities including walls for (var y = 0; y < map.Height; y++) { for (var x = 0; x < map.Width; x++) { var entity = map.GetEntity(x, y); if (entity == null) { continue; } Entity flippedEntity = null; if (entity.GetType() == typeof(Alien)) { flippedEntity = Alien.CopyAndFlip((Alien)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(Missile)) { flippedEntity = Missile.CopyAndFlip((Missile)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(Bullet)) { flippedEntity = Bullet.CopyAndFlip((Bullet)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(Shield)) { flippedEntity = Shield.CopyAndFlip((Shield)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(Ship)) { flippedEntity = Ship.CopyAndFlip((Ship)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(AlienFactory)) { flippedEntity = AlienFactory.CopyAndFlip((AlienFactory)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(MissileController)) { flippedEntity = MissileController.CopyAndFlip((MissileController)entity, flipper, flippedEntities); } else if (entity.GetType() == typeof(Wall)) { flippedEntity = Wall.CopyAndFlip((Wall)entity, flipper, flippedEntities); } if ((flippedEntity != null) && (copy.GetEntity(flippedEntity.X, flippedEntity.Y) == null)) { copy.AddEntity(flippedEntity); } } } return(copy); }
public static Player CopyAndFlip(Player player, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities) { var copy = new Player(player) { PlayerNumber = player.PlayerNumber == 1 ? 2 : 1 }; copy.Missiles.Clear(); foreach (var missile in player.Missiles) { copy.Missiles.Add(flippedEntities.ContainsKey(missile.Id) ? (Missile)flippedEntities[missile.Id] : Missile.CopyAndFlip(missile, flipper, flippedEntities)); } if (player.MissileController != null) { copy.MissileController = MissileController.CopyAndFlip(player.MissileController, flipper, flippedEntities); } if (player.AlienFactory != null) { copy.AlienFactory = AlienFactory.CopyAndFlip(player.AlienFactory, flipper, flippedEntities); } copy.AlienManager = AlienManager.CopyAndFlip(player.AlienManager, flipper, flippedEntities); if (player.Ship != null) { copy.Ship = Ship.CopyAndFlip(player.Ship, flipper, flippedEntities); } return(copy); }
public static Wall CopyAndFlip(Wall wall, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(wall.Id)) return (Wall) flippedEntities[wall.Id]; var copy = new Wall(wall) { X = flipper.CalculateFlippedX(wall.X), Y = flipper.CalculateFlippedY(wall.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static Ship CopyAndFlip(Ship ship, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(ship.Id)) return (Ship) flippedEntities[ship.Id]; var copy = new Ship(ship) { PlayerNumber = ship.PlayerNumber == 1 ? 2 : 1, X = flipper.CalculateFlippedX(ship.X + (ship.Width - 1)), Y = flipper.CalculateFlippedY(ship.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static Bullet CopyAndFlip(Bullet bullet, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(bullet.Id)) return (Bullet) flippedEntities[bullet.Id]; var copy = new Bullet(bullet) { PlayerNumber = bullet.PlayerNumber == 1 ? 2 : 1, X = flipper.CalculateFlippedX(bullet.X), Y = flipper.CalculateFlippedY(bullet.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static Missile CopyAndFlip(Missile missile, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(missile.Id)) return (Missile) flippedEntities[missile.Id]; var copy = new Missile(missile) { PlayerNumber = missile.PlayerNumber == 1 ? 2 : 1, X = flipper.CalculateFlippedX(missile.X), Y = flipper.CalculateFlippedY(missile.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static AlienFactory CopyAndFlip(AlienFactory alienFactory, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(alienFactory.Id)) return (AlienFactory) flippedEntities[alienFactory.Id]; var copy = new AlienFactory(alienFactory) { PlayerNumber = alienFactory.PlayerNumber == 1 ? 2 : 1, X = flipper.CalculateFlippedX(alienFactory.X + (alienFactory.Width - 1)), Y = flipper.CalculateFlippedY(alienFactory.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static Shield CopyAndFlip(Shield shield, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(shield.Id)) return (Shield) flippedEntities[shield.Id]; var copy = new Shield(shield) { PlayerNumber = shield.PlayerNumber == 1 ? 2 : 1, X = flipper.CalculateFlippedX(shield.X), Y = flipper.CalculateFlippedY(shield.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public static Alien CopyAndFlip(Alien alien, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { if (flippedEntities.ContainsKey(alien.Id)) return (Alien) flippedEntities[alien.Id]; var copy = new Alien(alien) { PlayerNumber = alien.PlayerNumber == 1 ? 2 : 1, DeltaX = -alien.DeltaX, DeltaY = -alien.DeltaY, X = flipper.CalculateFlippedX(alien.X), Y = flipper.CalculateFlippedY(alien.Y) }; flippedEntities.Add(copy.Id, copy); return copy; }
public IMatch GetFlippedCopyOfMatch() { var flippedEntities = new Dictionary <int, Entity>(); var flipper = new CoordinateFlipper(Map.Width, Map.Height); var flipped = new Match { BuildingsAvailable = BuildingsAvailable, RoundLimit = RoundLimit, RoundNumber = RoundNumber }; flipped.Players.Clear(); flipped.Map = Map.CopyAndFlip(Map, flipper, flippedEntities); flipped.Players.Add(Player.CopyAndFlip(GetPlayer(2), flipper, flippedEntities)); flipped.Players.Add(Player.CopyAndFlip(GetPlayer(1), flipper, flippedEntities)); return(flipped); }
public static AlienManager CopyAndFlip(AlienManager alienManager, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { var copy = new AlienManager(alienManager) { PlayerNumber = alienManager.PlayerNumber == 1 ? 2 : 1, DeltaX = -alienManager.DeltaX }; // Clear default copy of waves foreach (var wave in copy.Waves) { wave.Clear(); } copy.Waves.Clear(); // Copy waves flipped for (var i = alienManager.Waves.Count - 1; i >= 0; i--) { var wave = alienManager.Waves[i]; var waveList = new List<Alien>(); copy.Waves.Add(waveList); foreach (var alien in wave) { waveList.Add(Alien.CopyAndFlip(alien, flipper, flippedEntities)); } } return copy; }
public static Player CopyAndFlip(Player player, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { var copy = new Player(player) { PlayerNumber = player.PlayerNumber == 1 ? 2 : 1 }; copy.Missiles.Clear(); foreach (var missile in player.Missiles) { copy.Missiles.Add(flippedEntities.ContainsKey(missile.Id) ? (Missile) flippedEntities[missile.Id] : Missile.CopyAndFlip(missile, flipper, flippedEntities)); } if (player.MissileController != null) { copy.MissileController = MissileController.CopyAndFlip(player.MissileController, flipper, flippedEntities); } if (player.AlienFactory != null) { copy.AlienFactory = AlienFactory.CopyAndFlip (player.AlienFactory, flipper, flippedEntities); } copy.AlienManager = AlienManager.CopyAndFlip(player.AlienManager, flipper, flippedEntities); if (player.Ship != null) { copy.Ship = Ship.CopyAndFlip(player.Ship, flipper, flippedEntities); } return copy; }
public Map CopyAndFlip(Map map, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities) { var copy = new Map(map); // Copy all entities including walls for (var y = 0; y < map.Height; y++) { for (var x = 0; x < map.Width; x++) { var entity = map.GetEntity(x, y); if (entity == null) continue; Entity flippedEntity = null; if (entity.GetType() == typeof (Alien)) { flippedEntity = Alien.CopyAndFlip((Alien) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (Missile)) { flippedEntity = Missile.CopyAndFlip((Missile) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (Bullet)) { flippedEntity = Bullet.CopyAndFlip((Bullet) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (Shield)) { flippedEntity = Shield.CopyAndFlip((Shield) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (Ship)) { flippedEntity = Ship.CopyAndFlip((Ship) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (AlienFactory)) { flippedEntity = AlienFactory.CopyAndFlip((AlienFactory) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (MissileController)) { flippedEntity = MissileController.CopyAndFlip((MissileController) entity, flipper, flippedEntities); } else if (entity.GetType() == typeof (Wall)) { flippedEntity = Wall.CopyAndFlip((Wall) entity, flipper, flippedEntities); } if ((flippedEntity != null) && (copy.GetEntity(flippedEntity.X, flippedEntity.Y) == null)) { copy.AddEntity(flippedEntity); } } } return copy; }
public IMatch GetFlippedCopyOfMatch() { var flippedEntities = new Dictionary<int, Entity>(); var flipper = new CoordinateFlipper(Map.Width, Map.Height); var flipped = new Match { BuildingsAvailable = BuildingsAvailable, RoundLimit = RoundLimit, RoundNumber = RoundNumber }; flipped.Players.Clear(); flipped.Map = Map.CopyAndFlip(Map, flipper, flippedEntities); flipped.Players.Add(Player.CopyAndFlip(GetPlayer(2), flipper, flippedEntities)); flipped.Players.Add(Player.CopyAndFlip(GetPlayer(1), flipper, flippedEntities)); return flipped; }
private static Match CreateInterestingGameState(out CoordinateFlipper flipper) { var game = Match.GetInstance(); game.StartNewGame(); var map = game.Map; flipper = new CoordinateFlipper(map.Width, map.Height); var ship1 = game.GetPlayer(1).Ship; var ship2 = game.GetPlayer(2).Ship; // A rather lengthy sequence of moves to ensure every type of entity is on the map, including alien bullets... ship1.Command = ship2.Command = ShipCommand.MoveLeft; game.Update(); ship1.Command = ShipCommand.BuildAlienFactory; ship2.Command = ShipCommand.BuildMissileController; game.Update(); ship1.Command = ShipCommand.BuildShield; ship2.Command = ShipCommand.MoveRight; game.Update(); ship1.Command = ship2.Command = ShipCommand.MoveRight; game.Update(); ship1.Command = ship2.Command = ShipCommand.MoveRight; game.Update(); ship1.Command = ship2.Command = ShipCommand.Shoot; game.Update(); ship1.Command = ShipCommand.Nothing; ship2.Command = ShipCommand.MoveRight; game.Update(); ship1.Command = ShipCommand.Nothing; ship2.Command = ShipCommand.Shoot; game.Update(); return game; }