public static Tank getNearestEnemy(MainGrid mg, Graph g) { // Get the player location Vector2 playerLocation = mg.getTank(mg.Playername).Location; // get the nearest coin pile int dist = 1000; int tempDist; Tank nearestEnemy = new Tank(); foreach (Tank tank in mg.Tanks.Values.ToList<Tank>()) { tempDist = g.getPathByEntity(tank).Count; if (tank.Player_name == mg.Playername) continue; if (tempDist < dist) { dist = tempDist; nearestEnemy = tank; } } return nearestEnemy; }
// Adding and accessing tanks public void addTank(Tank t) { Tanks.Add(t.Player_name, t); }