/// <summary> /// Returns a list of the allied planets, ordered by ascending distance to the specified ally /// </summary> /// <returns>List of allies</returns> /// <param name="allies">Allies.</param> /// <param name="ally">Ally.</param> public IEnumerable<Planet> closestAllies(IEnumerable<Planet> allies, Planet ally) { allies = from Planet p in allies orderby Vector2.Distance(p.position, ally.position) where p.position != ally.position select p; return allies; }
/// <summary> /// Send one specific ship, change its target /// </summary> /// <param name="ship">Ship.</param> /// <param name="target">Target.</param> private bool Send(Ship ship, Planet target) { ship.target = target; return(true); }
/// <summary> /// Creates a new control object and starts the game. /// </summary> /// <param name="screenWidth">Screen width.</param> /// <param name="screenHeight">Screen height.</param> public Control(int screenWidth, int screenHeight) { this.screenWidth = screenWidth; this.screenHeight = screenHeight; sendOrders = new List <SendOrder>(); // initialize the game // create random planets and start the ai planets = new List <Planet>(); Random r = new Random(); for (int i = 0; i < planetCount; i++) { Planet testPlanet = new Planet(); testPlanet.playernumber = 1; testPlanet.radius = r.Next(minPlanetRadius, maxPlanetRadius); testPlanet.ships = startShips; testPlanet.timer = 0; Vector2 position = new Vector2(r.Next(testPlanet.radius, screenWidth / 2 - testPlanet.radius), r.Next(testPlanet.radius, screenHeight - testPlanet.radius)); while (planets.Exists(p => Vector2.Distance(p.position, position) < p.radius + testPlanet.radius)) { position = new Vector2(r.Next(testPlanet.radius, screenWidth / 2 - testPlanet.radius), r.Next(testPlanet.radius, screenHeight - testPlanet.radius)); } testPlanet.position = position; planets.Add(testPlanet); } r = new Random(); for (int i = 0; i < planetCount; i++) { Planet testPlanet = new Planet(); testPlanet.playernumber = 2; testPlanet.radius = r.Next(minPlanetRadius, maxPlanetRadius); testPlanet.ships = startShips; testPlanet.timer = 0; Vector2 position = new Vector2(r.Next(screenWidth / 2 + testPlanet.radius, screenWidth - testPlanet.radius), r.Next(screenWidth / 2 + testPlanet.radius, screenHeight - testPlanet.radius)); while (planets.Exists(p => Vector2.Distance(p.position, position) < p.radius + testPlanet.radius)) { position = new Vector2(r.Next(screenWidth / 2 + testPlanet.radius, screenWidth - testPlanet.radius), r.Next(screenWidth / 2 + testPlanet.radius, screenHeight - testPlanet.radius)); } testPlanet.position = position; Console.Out.WriteLine(position); planets.Add(testPlanet); } ships = new List <Ship>(); ais = new List <AI>(); JoinAI ai1 = new JoinAI(); ai1.playernumber = 1; ai1.control = this; JoinAI ai2 = new JoinAI(); ai2.playernumber = 2; ai2.control = this; ais.Add(ai1); ais.Add(ai2); explosions = new List <Explosion>(); }
public SendOrder(Planet from, Planet to, int amount) { this.from = from; this.to = to; this.amount = amount; }