Ejemplo n.º 1
0
 /// <summary>
 /// Retrieves a "good" destination for the current selected unit.
 /// A "good" destination is a destination with no enemy on it that is not a sea position.
 /// </summary>
 /// <param name="game">The game</param>
 /// <param name="currentPos">The current position of the unit.</param>
 /// <param name="unit">The unit.</param>
 /// <returns>The destination choosen.</returns>
 private IPoint GetDestination(IGame game, IPoint currentPos, IUnit unit)
 {
     int[] xOffsets = new int[4] {0, -1, 1, 0};
     int[] yOffsets = new int[4] {-1, 0, 0, 1};
     for(int i=0; i<4; i++) {
         IPoint destination = new Point(currentPos.X + xOffsets[i], currentPos.Y + yOffsets[i]);
         if(destination.isValid(game.Map.Size)) {
             if(!(game.Map.GetTile(destination) is ISea) && !game.Map.IsEnemyPosition(destination, unit)) {
                 return destination;
             }
         }
     }
     // We decided to fail in that case as it is hightly improbable that
     // no vacant destination point is available.
     // Indeed our map is made so that every position can be reached.
     Assert.Fail("nothing next to " + currentPos);
     return null;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Retrieves the neighbours' types of a specific position.
 /// </summary>
 /// <param name="pos">The position.</param>
 /// <returns>An array of neighbours' types, or null if a neighbour was out bounds.</returns>
 private ITile[] GetNeighbours(IPoint pos)
 {
     int[] xOffset = {0, -1, 0, 1};
     int[] yOffset = {0, -1, 0, 1};
     ITile[] neighbours = new ITile[4];
     for(int i=0; i<4; i++) {
         IPoint neighbour = new Point(pos.X + xOffset[i], pos.Y + yOffset[i]);
         if(neighbour.isValid(this.map.Size)) {
             neighbours[i] = this.map.GetTile(neighbour);
         } else {
             neighbours[i] = null;
         }
     }
     return neighbours;
 }