private Ship(Ship ship) : base(ship) { OnDestroyedEvent += OnDestroy; Command = ship.Command; CommandFeedback = ship.CommandFeedback; }
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 void TestAddEntity() { // Given var game = Match.GetInstance(); game.StartNewGame(); var map = new Map(11, 11); game.Map = map; var ship = new Ship(1) {X = 1, Y = 2}; // When map.AddEntity(ship); // Then Assert.IsNotNull(map.GetEntity(ship.X, ship.Y), "Entity is null when it should be a space ship"); Assert.IsNotNull(map.GetEntity(ship.X + 1, ship.Y), "Entity is null when it should be a space ship"); Assert.IsNotNull(map.GetEntity(ship.X + 2, ship.Y), "Entity is null when it should be a space ship"); Assert.IsNull(map.GetEntity(ship.X + 3, ship.Y), "Entity is not null when it should be"); }
public void TestRemoveEntity() { // Given var game = Match.GetInstance(); game.StartNewGame(); var map = new Map(11, 11); game.Map = map; var ship = new Ship(1) {X = 1, Y = 2}; map.AddEntity(ship); // When map.RemoveEntity(ship); // Then Assert.IsNull(map.GetEntity(ship.X, ship.Y), "Entity should be null"); Assert.IsNull(map.GetEntity(ship.X + 1, ship.Y), "Entity should be null"); Assert.IsNull(map.GetEntity(ship.X + 2, ship.Y), "Entity should be null"); }
private void OnShipKilled(object sender, EventArgs e) { Ship = null; RespawnTimer = Settings.Default.RespawnDelay; }
public void SpawnShip() { var map = Match.GetInstance().Map; var ship = new Ship(PlayerNumber) { X = map.Width/2 - 1, Y = PlayerNumber == 1 ? map.Height - 3 : 2 }; ship.OnDestroyedEvent += OnShipKilled; try { if (Match.GetInstance().GetRoundNumber() > 0) Lives--; map.AddEntity(ship); Ship = ship; } catch (CollisionException e) { foreach (Entity entity in e.Entities) { if (entity.GetType() == typeof (Missile)) { ((Missile) entity).ScoreKill(ship); entity.Destroy(); ship.Destroy(); } else if (entity.GetType() == typeof (Alien) || entity.GetType() == typeof (Bullet)) { entity.Destroy(); ship.Destroy(); } } } }
private void BuildBuilding(Ship ship, Match game) { ship.Command = GetCommandForBuildingUnderTest(); game.Update(); }