public static void drawUnit(Graphics g, int gridWidth, int gridHeight, Unit unit, Brush color) { int unitX = 5 + (unit.x * gridWidth) + (int)(gridWidth * 0.5); int unitY = 5 + (unit.y * gridHeight) + (int)(gridHeight * 0.5); Rectangle unitBaseRect = new Rectangle(unitX - (int)(gridWidth * 2.4), unitY - (int)(gridHeight * 2.4), (int)(gridWidth * 4.8), (int)(gridHeight * 4.8)); Rectangle unitGunRect = new Rectangle(unitX - (int)(gridWidth * 0.2), unitY - (int)(gridHeight * 0.2), (int)(gridWidth * 0.4), (int)(gridHeight * 0.4)); Rectangle unitHatchRect = new Rectangle(unitX - (int)(gridWidth * 0.4), unitY - (int)(gridHeight * 0.4), (int)(gridWidth * 0.8), (int)(gridHeight * 0.8)); switch (unit.direction) { case Direction.UP: unitGunRect.Y -= (int)(gridHeight * 1.8); unitGunRect.Height = (int)(gridHeight * 2); break; case Direction.DOWN: unitGunRect.Height = (int)(gridHeight * 2); break; case Direction.LEFT: unitGunRect.X -= (int)(gridWidth * 1.8); unitGunRect.Width = (int)(gridWidth * 2); break; case Direction.RIGHT: unitGunRect.Width = (int)(gridWidth * 2); break; } g.FillRectangle(color, unitBaseRect); g.FillRectangle(Brushes.Black, unitGunRect); g.FillEllipse(color, unitHatchRect); g.DrawEllipse(Pens.Black, unitHatchRect); }
public Unit(Unit source) { this.x = source.x; this.y = source.y; this.action = source.action; this.direction = source.direction; this.id = source.id; }
public static Size DistanceBetween(Unit tank, Point pt) { return DistanceBetween(tank.x, tank.y, pt.X, pt.Y); }
public static Size DistanceBetween(Unit tank, int x, int y) { return DistanceBetween(tank.x, tank.y, x, y); }
public static Size DistanceBetween(Unit tank1, Unit tank2) { return DistanceBetween(tank1.x, tank1.y, tank2.x, tank2.y); }
public static Size DistanceBetween(Unit tank, Base playerBase) { return DistanceBetween(tank.x, tank.y, playerBase.x, playerBase.y); }
private void destroyUnit(Unit unit) { for (int playerIdx = 0; playerIdx < 2; playerIdx++) { this.players[playerIdx].units.Remove(unit); } }
private Unit anyUnitAt(int x, int y, Unit excl) { for (int playerIdx = 0; playerIdx < 2; playerIdx++) { foreach (Unit unit in this.players[playerIdx].units) { if ((x >= unit.x - 2) && (x <= unit.x + 2) && (y >= unit.y - 2) && (y <= unit.y + 2) && ((excl == null) || (excl.id != unit.id))) { return unit; } } } return null; }