public Direction Directionto(Unit u) { if (u.GetType() == typeof(MeeleeUnit)) { MeeleeUnit m = (MeeleeUnit)u; if (m.Xpos < Xpos) { return(Direction.North); } else if (m.Xpos > Xpos) { return(Direction.South); } else if (m.Ypos < Ypos) { return(Direction.West); } else { return(Direction.East); } } else { return(Direction.North); } }
private int DistanceTo(Unit u) { if (u.GetType() == typeof(MeeleeUnit)) { MeeleeUnit m = (MeeleeUnit)u; int d = Math.Abs(Xpos - m.Xpos) + Math.Abs(Ypos - m.Ypos); return(d); } else { return(0); } }
public override bool AttackRange(Unit u) { if (u.GetType() == typeof(MeeleeUnit)) { MeeleeUnit M = (MeeleeUnit)u; if (DistanceTo(u) <= attackRange) { return(true); } else { return(false); } } return(false); }
public Map(int maxX, int maxY, int numUnits) { units = new Unit[numUnits]; for (int i = 0; i < numUnits; i++) { if (i <= 10) { MeeleeUnit M = new MeeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, r.Next(5, 20), 1, 1, i % 2, "ground.jpg", "archer"); Units[i] = M; } if (i > 10) { RangedUnit R = new RangedUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, r.Next(5, 20), 1, 1, i % 2, "ground.jpg", "archer"); Units[i] = R; } } }
private void DisplayMap() { groupBox1.Controls.Clear(); foreach (Unit u in map.Units) { if (u.GetType() == typeof(MeeleeUnit)) { int start_x = 20; int start_Y = 20; start_x = groupBox1.Location.X; start_Y = groupBox1.Location.Y; MeeleeUnit m = (MeeleeUnit)u; PictureBox Pbox = new PictureBox(); Pbox.Size = new Size(Size, Size); Pbox.Location = new Point(start_x + (m.Xpos * Size), start_Y + (m.Ypos * Size)); Pbox.SizeMode = PictureBoxSizeMode.Zoom; Pbox.ImageLocation = "ground.jpg"; if (m.Fact == 1) { Pbox.ImageLocation = "red.png"; } else { Pbox.ImageLocation = "red.png"; } if (m.isDead()) { Pbox.ImageLocation = "ground.jpg"; } groupBox1.Controls.Add(Pbox); Pbox.Click += new EventHandler(Picture_Click); } } foreach (Unit u in map.Units) { if (u.GetType() == typeof(RangedUnit)) { int start_x = 20; int start_Y = 20; start_x = groupBox1.Location.X; start_Y = groupBox1.Location.Y; RangedUnit m = (RangedUnit)u; PictureBox Pbox = new PictureBox(); Pbox.Size = new Size(Size, Size); Pbox.Location = new Point(start_x + (m.Xpos * Size), start_Y + (m.Ypos * Size)); Pbox.SizeMode = PictureBoxSizeMode.Zoom; Pbox.ImageLocation = "ground.jpg"; if (m.Fact == 1) { Pbox.ImageLocation = "purple.png"; } else { Pbox.ImageLocation = "purple.png"; } if (m.isDead()) { Pbox.ImageLocation = "DirtGround.jpg"; } groupBox1.Controls.Add(Pbox); Pbox.Click += new EventHandler(Picture_Click); } } }
private void UpdateMap() { foreach (Unit u in map.Units) { if (u.GetType() == typeof(MeeleeUnit)) { MeeleeUnit m = (MeeleeUnit)u; if (m.health < 25) { switch (r.Next(0, 4)) { case 0: ((MeeleeUnit)u).NewMovePos(Direction.North); break; case 1: ((MeeleeUnit)u).NewMovePos(Direction.East); break; case 2: ((MeeleeUnit)u).NewMovePos(Direction.South); break; case 3: ((MeeleeUnit)u).NewMovePos(Direction.West); break; } } else { bool inCombat = false; foreach (Unit e in map.Units) { if (u.AttackRange(e)) { u.Combat(e); inCombat = true; } } if (!inCombat) { Unit c = u.UnitDistance(map.Units); m.NewMovePos(m.Directionto(c)); } } } } foreach (Unit u in map.Units) { if (u.GetType() == typeof(RangedUnit)) { RangedUnit m = (RangedUnit)u; if (m.health < 25) { switch (r.Next(0, 4)) { case 0: ((RangedUnit)u).NewMovePos(Direction.North); break; case 1: ((RangedUnit)u).NewMovePos(Direction.East); break; case 2: ((RangedUnit)u).NewMovePos(Direction.South); break; case 3: ((RangedUnit)u).NewMovePos(Direction.West); break; } } else { bool inCombat = false; foreach (Unit e in map.Units) { if (u.AttackRange(e)) { u.Combat(e); inCombat = true; } } if (!inCombat) { Unit c = u.UnitDistance(map.Units); m.NewMovePos(m.Directionto(c)); } } } } }