private void RadarShipTurn(RadarShip ship) { bool f = false; for (int i = ship.Position.X - ship.Visibility >= 0 ? ship.Position.X - ship.Visibility : 0; i < (ship.Position.X + ship.Visibility <= space.Width ? ship.Position.X + ship.Visibility : space.Width); i++) { for (int j = ship.Position.Y - ship.Visibility >= 0 ? ship.Position.Y - ship.Visibility : 0; i < (ship.Position.Y + ship.Visibility <= space.Width ? ship.Position.Y + ship.Visibility : space.Width); j++) { if (space[i, j] is WarShip && (space[i, j] as SpaceShip).Armor > 0 && (space[i, j] as SpaceShip).Color != ship.Color) { ship.Retreat(space[i, j]); f = true; } if (f) { break; } } if (f) { break; } } if (!f) { Random rand = new Random(); LocatableObject p = planets[rand.Next(planets.Count)]; ship.MoveTo(p.Position); } }
public void Retreat(LocatableObject obj) { animationState = ShipAnimationState.None; path = null; Location target = new Location(Position.X, Position.Y); for (int i = 0; i < speed; i++) { if (Position.X > obj.Position.X) { target.X++; } if (Position.X <= obj.Position.X) { target.X--; } if (Position.Y > obj.Position.Y) { target.Y++; } if (Position.Y <= obj.Position.Y) { target.Y--; } if (target.X < 0) { target.X = 0; } if (target.Y < 0) { target.Y = 0; } if (target.X > space.Width) { target.X = space.Width; } if (target.Y > space.Height) { target.Y = space.Height; } MoveTo(target); } }
public override void Attack(LocatableObject obj) { animationState = ShipAnimationState.None; path = null; SpaceShip ship = (SpaceShip)obj; for (int i = 0; i < speed; i++) { if (Math.Sqrt(Math.Pow(ship.Position.X - Position.X, 2) + Math.Pow(ship.Position.Y - Position.Y, 2)) <= visibility * 0.8) { fire(ship); break; } else { MoveTo(ship.Position); } } }
private void WarShipTurn(WarShip ship) { if (ship is IRegeneration) { (ship as IRegeneration).Regeneration(); } bool f = false; for (int i = ship.Position.X - ship.Visibility >= 0 ? ship.Position.X - ship.Visibility : 0; i < (ship.Position.X + ship.Visibility <= space.Width ? ship.Position.X + ship.Visibility : space.Width); i++) { for (int j = ship.Position.Y - ship.Visibility >= 0 ? ship.Position.Y - ship.Visibility : 0; i < (ship.Position.Y + ship.Visibility <= space.Width ? ship.Position.Y + ship.Visibility : space.Width); j++) { if (space[i, j] is SpaceShip && (space[i, j] as SpaceShip).Armor > 0 && (space[i, j] as SpaceShip).Color != ship.Color) { if (Math.Sqrt(Math.Pow(i - ship.Position.X, 2) + Math.Pow(j - ship.Position.Y, 2)) <= ship.Visibility) { if (space[i, j] is IStealth && !(space[i, j] as IStealth).StealthOn() || !(space[i, j] is IStealth)) { ship.Attack(space[i, j]); f = true; } } } if (f) { break; } } if (f) { break; } } if (!f) { Random rand = new Random(); LocatableObject p = planets[rand.Next(planets.Count)]; ship.MoveTo(p.Position); } }
public override void Attack(LocatableObject obj) { Retreat(obj); }
public abstract void Attack(LocatableObject obj);
private void PlanetTurn(Planet planet) { if (numberWarShip >= MAXWARSHIP && numberRadarShip >= MAXRADARSHIP && numberTransportShip >= MAXTRANSPORTSHIP && (numberStealthShip >= MAXSTEALTHSHIP || numberRegenShip >= MAXREGENSHIP) || planet.Resources < 75) { return; } LocatableObject w = null; Random rand = new Random(); if (numberWarShip < 2) { w = planet.CreateWarShip(warShipPrice, warShipParameters); if (w != null) { units.Add(w); } numberWarShip++; return; } if (numberTransportShip < 3) { w = planet.CreateTransportShip(transportShipPrice, transportShipParameters); if (w != null) { units.Add(w); } numberTransportShip++; return; } Boolean[] f = { true, true, true, true }; while (w == null && f[0] && f[1] && f[2] && f[3]) { switch (rand.Next(4)) { case 0: if (numberTransportShip < MAXTRANSPORTSHIP) { w = planet.CreateTransportShip(transportShipPrice, transportShipParameters); } f[0] = false; break; case 1: if (numberRadarShip < MAXRADARSHIP) { w = planet.CreateRadarShip(radarShipPrice, radarShipParameters); numberRadarShip++; } f[1] = false; break; case 2: if (numberWarShip < MAXWARSHIP) { w = planet.CreateWarShip(warShipPrice, warShipParameters); numberWarShip++; } f[2] = false; break; case 3: if (raceType) { if (numberRegenShip < MAXREGENSHIP) { w = planet.CreateRegenShip(regenShipPrice, regenShipParameters); numberRegenShip++; } f[3] = false; } else { if (numberStealthShip < MAXSTEALTHSHIP) { w = planet.CreateStealthShip(stealthShipPrice, stealthShipParameters); numberStealthShip++; } f[3] = false; } break; } } if (w != null) { units.Add(w); } }