public GameState(int width, int height, int turntime, int loadtime, int viewradius2, int attackradius2, int spawnradius2) { Width = width; Height = height; LoadTime = loadtime; TurnTime = turntime; ViewRadius2 = viewradius2; AttackRadius2 = attackradius2; SpawnRadius2 = spawnradius2; MyAnts = new List<AntLoc>(); EnemyAnts = new List<AntLoc>(); DeadTiles = new List<Location>(); FoodTiles = new List<Location>(); Map = new Tile[height, width]; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { Map[row, col] = new Tile(TileType.Land, new Location(this, row, col)); } } }
public void checkDead() { int antsAround = 0; Tile[] surround = new Tile[6]; if (y % 2 == 0) { surround[0] = myLogic.getTile(x + 1, y); surround[1] = myLogic.getTile(x, y + 1); surround[2] = myLogic.getTile(x - 1, y + 1); surround[3] = myLogic.getTile(x - 1, y); surround[4] = myLogic.getTile(x - 1, y - 1); surround[5] = myLogic.getTile(x, y - 1); } else { surround[0] = myLogic.getTile(x + 1, y); surround[1] = myLogic.getTile(x + 1, y + 1); surround[2] = myLogic.getTile(x, y + 1); surround[3] = myLogic.getTile(x - 1, y); surround[4] = myLogic.getTile(x, y - 1); surround[5] = myLogic.getTile(x + 1, y - 1); } for (int i = 0; i < 6; i++) { if (surround[i].getAnt() && !surround[i].getColour().Equals(this.colour)) { antsAround++; } } if (antsAround > 4) { setDead(); if(carryingFood) { myLogic.loadTile(x, y, myLogic.texTileFood, myLogic.spriteBatch, false, false, true, 4 + myTile.getNumFood(), false, null); } else { myLogic.loadTile(x, y, myLogic.texTileFood, myLogic.spriteBatch, false, false, true, 3 + myTile.getNumFood(), false, null); } } }
public Ant(Game game, Logic MyLogic, String Colour, int X, int Y, int Dir, int id) : base(game) { state = 0; restingNum = 0; carryingFood = false; isAlive = true; resting = false; colour = Colour; x = X; y = Y; dir = Dir; ID = id; myLogic = MyLogic; myTile = myLogic.getTile(x, y); if(colour.Equals("red")) { myLogic.loadTile(x, y, myLogic.texAntsOnHillRed[0], myLogic.spriteBatch, false, true, false, 0, true, "red"); } else if (colour.Equals("black")) { myLogic.loadTile(x, y, myLogic.texAntsOnHillBlack[0], myLogic.spriteBatch, false, true, false, 0, true, "black"); } }
internal void addWater(int row, int col) { Map[row, col] = new Tile(TileType.Water, new Location(this, row, col)); }
internal void addFood(int row, int col) { var loc = new Location(this, row, col); Map[row, col] = new Tile(TileType.Food, loc); FoodTiles.Add(loc); }
internal void addAnt(int row, int col, int team) { AntLoc ant = new AntLoc(this, row, col, team); Map[row, col] = new Tile(TileType.Ant, ant); if (team == 0) { MyAnts.Add(ant); } else { EnemyAnts.Add(ant); } }
public void SetTile(Location loc, Tile tile) { Map[loc.X, loc.Y] = tile; }
/// <summary> /// Gets the closest directions to get from <paramref name="loc1"/> to <paramref name="loc2"/>. /// </summary> /// <param name="loc1">The location to start from.</param> /// <param name="loc2">The location to determine directions towards.</param> /// <returns>The 1 or 2 closest directions from <paramref name="loc1"/> to <paramref name="loc2"/></returns> public static ICollection<Direction> GetDirections(Tile loc1, Tile loc2) { List<Direction> directions = new List<Direction>(); if (loc1.Row < loc2.Row) { if (loc2.Row - loc1.Row >= MapHeight / 2) directions.Add(Direction.North); if (loc2.Row - loc1.Row <= MapHeight / 2) directions.Add(Direction.South); } if (loc2.Row < loc1.Row) { if (loc1.Row - loc2.Row >= MapHeight / 2) directions.Add(Direction.South); if (loc1.Row - loc2.Row <= MapHeight / 2) directions.Add(Direction.North); } if (loc1.Col < loc2.Col) { if (loc2.Col - loc1.Col >= MapWidth / 2) directions.Add(Direction.West); if (loc2.Col - loc1.Col <= MapWidth / 2) directions.Add(Direction.East); } if (loc2.Col < loc1.Col) { if (loc1.Col - loc2.Col >= MapWidth / 2) directions.Add(Direction.East); if (loc1.Col - loc2.Col <= MapWidth / 2) directions.Add(Direction.West); } return directions; }
//made this method just to place all the tiles on the screen. all blank except rocky round the edges private void LoadTiles(SpriteBatch spriteBatch) { for (int y = 0; y < 150; y++) { for (int x = 0; x < 150; x++) { if (y % 2 == 0) { if (x == 0 || x == 149 || y == 0 || y == 149) { tiles[x, y] = new Tile(this, texTileRocky, new Vector2(x * 6, y * 6), spriteBatch, true, false, false, 0, false, "", 0, 0); } else { tiles[x, y] = new Tile(this, texTileBlank, new Vector2(x * 6, y * 6), spriteBatch, false, false, false, 0, false, "", 0, 0); } } else { if (x == 0 || x == 149 || y == 0 || y == 149) { tiles[x, y] = new Tile(this, texTileRocky, new Vector2((x * 6) + 3, y * 6), spriteBatch, true, false, false, 0, false, "", 0, 0); } else { tiles[x, y] = new Tile(this, texTileBlank, new Vector2((x * 6) + 3, y * 6), spriteBatch, false, false, false, 0, false, "", 0, 0); } } } } }
public void move() { myTile = myLogic.getTile(x, y); if (sense("ahead").getRocky() == false && sense("ahead").getAnt() == false) { if (myTile.getFood()) { myLogic.loadTile(x, y, myLogic.texTileFood, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, null); } else if (myTile.getAntHill()) { if (myTile.getColour().Equals(this.colour)) { if (colour.ToLower().Equals("red")) { myLogic.loadTile(x, y, myLogic.texAntHillRed, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, "red"); } else if (colour.ToLower().Equals("black")) { myLogic.loadTile(x, y, myLogic.texAntHillBlack, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, "black"); } } else { if (colour.ToLower().Equals("red")) { myLogic.loadTile(x, y, myLogic.texAntHillBlack, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, "black"); } else if (colour.ToLower().Equals("black")) { myLogic.loadTile(x, y, myLogic.texAntHillRed, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, "red"); } } } else { myLogic.loadTile(x, y, myLogic.texTileBlank, myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), false, null); } switch (dir) { case 0: x++; break; case 1: if (y % 2 == 0) { y++; } else { x++; y++; } break; case 2: if (y % 2 == 0) { x--; y++; } else { y++; } break; case 3: x--; break; case 4: if (y % 2 == 0) { x--; y--; } else { y--; } break; case 5: if (y % 2 == 0) { y--; } else { x++; y--; } break; } Tile oldTile = myTile; myTile = myLogic.getTile(x, y); if (colour.ToLower().Equals("red")) { if (myTile.getFood()) { myLogic.loadTile(x, y, myLogic.texAntsOnFoodRed[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } else if (myTile.getAntHill()) { if (myTile.getColour().Equals(this.colour)) { myLogic.loadTile(x, y, myLogic.texAntsOnHillRed[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } else { myLogic.loadTile(x, y, myLogic.texAntsOnHillRed[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, oldTile.getColour()); } } else { myLogic.loadTile(x, y, myLogic.texAntsBlankRed[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } } else if (colour.ToLower().Equals("black")) { if (myTile.getFood()) { myLogic.loadTile(x, y, myLogic.texAntsOnFoodBlack[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } else if (myTile.getAntHill()) { myLogic.loadTile(x, y, myLogic.texAntsOnHillBlack[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } else { myLogic.loadTile(x, y, myLogic.texAntsBlankBlack[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } } } }
public void loadTile(int x, int y, Texture2D tex, SpriteBatch spriteBatch, Boolean rocky, Boolean antHill, Boolean food, int numFood, Boolean ant, String antColour) { Vector2 newPos = new Vector2(tiles[x, y].getPos("x"), tiles[x, y].getPos("y")); tiles[x, y] = new Tile(this, tex, newPos, spriteBatch, rocky, antHill, food, numFood, ant, antColour, 0, 0); }
static void InitMap() { map = new Tile[MapHeight, MapWidth]; for (int row = 0; row < MapHeight; row++) for (int col = 0; col < MapWidth; col++) map[row, col] = new Tile(row, col, TileType.Unseen); }
/// <summary> /// Gets the distance between <paramref name="loc1"/> and <paramref name="loc2"/>. /// </summary> /// <param name="loc1">The first location to measure with.</param> /// <param name="loc2">The second location to measure with.</param> /// <returns>The distance between <paramref name="loc1"/> and <paramref name="loc2"/></returns> public static int GetDistance(Tile loc1, Tile loc2) { int d_row = Math.Abs(loc1.Row - loc2.Row); d_row = Math.Min(d_row, MapHeight - d_row); int d_col = Math.Abs(loc1.Col - loc2.Col); d_col = Math.Min(d_col, MapWidth - d_col); return d_row + d_col; }
internal void deadAnt(int row, int col) { // food could spawn on a spot where an ant just died // don't overwrite the space unless it is land var loc = new Location(this, row, col); if (Map[row, col].Type == TileType.Land) { Map[row, col] = new Tile(TileType.Dead, loc); } // but always add to the dead list DeadTiles.Add(loc); }
public void turn(String lr) { myTile = myLogic.getTile(x, y); if (lr.ToLower().Equals("left")) { if (dir == 0) { dir = 5; } else { dir--; } } else if (lr.ToLower().Equals("right")) { if (dir == 5) { dir = 0; } else { dir++; } } if (colour.ToLower().Equals("red")) { myLogic.loadTile(x, y, myLogic.texAntsOnHillRed[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } else if (colour.ToLower().Equals("black")) { myLogic.loadTile(x, y, myLogic.texAntsOnHillBlack[dir], myLogic.spriteBatch, myTile.getRocky(), myTile.getAntHill(), myTile.getFood(), myTile.getNumFood(), true, colour); } }
internal void removeFood(int row, int col) { // an ant could move into a spot where a food just was // don't overwrite the space unless it is food var loc = new Location(this, row, col); if (Map[row, col].Type == TileType.Food) { Map[row, col] = new Tile(TileType.Land, loc); } FoodTiles.Remove(loc); }
public static void AddWater(int row, int col) { map[row, col] = new Tile(row, col, TileType.Water); }