private void pnlContainer_MouseUp(object sender, MouseEventArgs e) { int x = (int)(e.X / (float)pnlContainer.Width * Environment.envW); int y = (int)(e.Y / (float)pnlContainer.Height * Environment.envH); if (e.Button == MouseButtons.Right) { environment.remove(x, y); txtHumans.Text = environment.count(new Human(environment)).ToString(); txtMammoths.Text = environment.count(new Mammoth(environment)).ToString(); txtPlants.Text = environment.count(new Plant(environment)).ToString(); txtObstacles.Text = environment.count(new Stone(environment)).ToString(); environment.draw(); } else if (e.Button == MouseButtons.Middle) { Entity add; if (cmbAdd.Text == "Mammoth") add = new Mammoth(environment); else if (cmbAdd.Text == "Human") add = new Human(environment); else if (cmbAdd.Text == "Plant") add = new Plant(environment); else if (cmbAdd.Text == "Stone") add = new Stone(environment); else return; Entity ent = environment.getNearest(x, y, add); if (ent != null) MessageBox.Show(environment.getDistance(x, y, ent.x, ent.y).ToString()); } else { Entity ent = environment.get(x, y); if (ent != null) { txtActions.Text = ("Info:\r\n" + ent.getInfo() + "\r\n(x, y):(" + x + "," + y + ")"); } } }
private void pnlContainer_MouseDoubleClick(object sender, MouseEventArgs e) { Entity add = null; if (cmbAdd.Text == "Mammoth") add = new Mammoth(environment); else if (cmbAdd.Text == "Human") add = new Human(environment); else if (cmbAdd.Text == "Plant") add = new Plant(environment); else if (cmbAdd.Text == "Stone") add = new Stone(environment); int x = (int)(e.X / (float)pnlContainer.Width * Environment.envW); int y = (int)(e.Y / (float)pnlContainer.Height * Environment.envH); if (add != null) add.init(); if (environment.get(x, y) == null && add != null) environment.add(add, x, y); else if (environment.get(x, y) is Human) { Human h = (Human)environment.get(x, y); h.strategy = (Strategies)(((int)h.strategy + 1) % 4); } txtHumans.Text = environment.count(new Human(environment)).ToString(); txtMammoths.Text = environment.count(new Mammoth(environment)).ToString(); txtPlants.Text = environment.count(new Plant(environment)).ToString(); txtObstacles.Text = environment.count(new Stone(environment)).ToString(); environment.draw(); }