public void Building_Click(object sender, EventArgs e) { int x, y; Button b = (Button)sender; x = b.Location.X / 20; y = b.Location.Y / 20; foreach (Building bu in buildings) { if (bu is FactoryBuilding) { FactoryBuilding fb = (FactoryBuilding)bu; if (fb.Xpos == x && fb.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = fb.ToString(); } } else if (bu is ResourceBuilding) { ResourceBuilding rb = (ResourceBuilding)bu; if (rb.Xpos == x && rb.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = rb.ToString(); } //when a building is clicked, ToString is called } } }
public void Unit_Click(object sender, EventArgs e) { int x, y; Button b = (Button)sender; x = b.Location.X / 20; y = b.Location.Y / 20; foreach (Unit u in units) { if (u is RangedUnit) { RangedUnit ru = (RangedUnit)u; if (ru.Xpos == x && ru.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = ru.ToString(); } } else if (u is MeleeUnit) { MeleeUnit mu = (MeleeUnit)u; if (mu.Xpos == x && mu.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = mu.ToString(); } } else if (u is WizardUnit) { WizardUnit wu = (WizardUnit)u; if (wu.Xpos == x && wu.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = wu.ToString(); } } } foreach (Building bu in buildings) { if (bu is FactoryBuilding) { FactoryBuilding fb = (FactoryBuilding)bu; if (fb.Xpos == x && fb.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = fb.ToString(); } } else if (bu is ResourceBuilding) { ResourceBuilding rb = (ResourceBuilding)bu; if (rb.Xpos == x && rb.Ypos == y) { txtInfo.Text = ""; txtInfo.Text = rb.ToString(); } //when a building is clicked, ToString is called } } }
public void Generate() { // int rng = r.Next(0, 2); for (int i = 0; i < numUnits; i++) { if (r.Next(0, 2) == 0) { MeleeUnit m = new MeleeUnit(r.Next(0, 20), r.Next(0, 20), 100, 1, 20, (i % 2 == 0 ? 1 : 0), "M", "Grunt"); units.Add(m); } else if (r.Next(0, 2) == 1) { RangedUnit ru = new RangedUnit(r.Next(0, 20), r.Next(0, 20), 100, 1, 20, 5, (i % 2 == 0 ? 1 : 0), "R", "Archer"); units.Add(ru); } else { WizardUnit wu = new WizardUnit(r.Next(0, 20), r.Next(0, 20), 100, 1, 20, 10, (i % 2 == 0 ? 1 : 0), "W", "Wizard"); units.Add(wu); } } for (int i = 0; i < numBuildings; i++) { if (r.Next(0, 2) == 0) { FactoryBuilding fb = new FactoryBuilding(r.Next(0, 20), r.Next(0, 20), 200, r.Next(0, 2), "F"); buildings.Add(fb); } else { ResourceBuilding rb = new ResourceBuilding(r.Next(0, 20), r.Next(0, 20), 200, r.Next(0, 2), "RB"); buildings.Add(rb); } } }