private static ISpace[,] AttackDrone(int currentX, int currentY, int targetX, int targetY, ISpace[,] previousMap) { var map = previousMap; //Validate currentCoords are actually a drone if (!(map[currentX, currentY] is Drone)) { throw new Exception($"Failed to attack with drone at {map[currentX, currentY]} as it is not a drone"); } //Validate target is a drone if (map[targetX, targetY] is Drone == false) { throw new Exception($"Failed to attack drone at {map[targetX, targetY]} as that space is not a drone"); } //Move drone into the target space, swapping with a drone if moving into it's space var targetDrone = map[targetX, targetY] as Drone; if (targetDrone != null) { map[targetX, targetY] = new Explored(100); } return(map); }
private static ISpace[,] MoveDrone(int currentX, int currentY, int targetX, int targetY, ISpace[,] previousMap) { var map = previousMap; //Validate currentCoords are actually a drone if (!(map[currentX, currentY] is Drone)) { return(map); } //Validate target is not solid if (map[targetX, targetY].IsSolid()) { throw new Exception($"Failed to move drone into {map[targetX, targetY]} as that space is solid"); } //Move drone into the target space, swapping with a drone if moving into it's space var targetDrone = map[targetX, targetY] as Drone; var currentDrone = map[currentX, currentY] as Drone; if (targetDrone != null) { var temp = map[targetX, targetY]; map[currentX, currentY] = map[targetX, targetY]; map[targetX, targetY] = temp; } else { map[targetX, targetY] = map[currentX, currentY]; map[currentX, currentY] = new Explored(currentDrone.State == EntityType.UngroupedDrone ? 100 : 0); } return(map); }