private void Event_Launcher(object sender, MouseEventArgs e) { int i = 0; MessageBox.Show((agrandissement + 1) + ""); courbe = new Point[graph.Width / agrandissement + 1]; while (obj_tennis.getPosY() > 0) { but_tennis.Location = new Point((int)(graph.Location.X + obj_tennis.getPosX() * agrandissement), (int)(graph.Location.Y + graph.Height - obj_tennis.getPosY() * agrandissement)); courbe[i] = new Point(but_tennis.Location.X - graph.Location.X, but_tennis.Location.Y - graph.Location.Y); i++; obj_tennis.setPosX(obj_tennis.getPosX() + 1); obj_tennis.setPosY(envi.CalculTrajectoire(obj_tennis, obj_tennis.getPosX())); } double lastX = Solve(-(envi.getGravity() / (2 * Math.Pow(envi.getVit0(), 2) * Math.Pow(Math.Cos(envi.DegToRad(envi.getAngle())), 2))), Math.Tan(envi.DegToRad(envi.getAngle())), obj_tennis.getPosY0())[0]; obj_tennis.setPosX(lastX); but_tennis.Location = new Point((int)(graph.Location.X + obj_tennis.getPosX() * agrandissement), graph.Location.Y + graph.Height - but_tennis.Height); courbe[i] = new Point(but_tennis.Location.X - graph.Location.X, but_tennis.Location.Y - graph.Location.Y + but_tennis.Height); Array.Resize(ref courbe, i + 1); if ((this.Width - 10) / agrandissement > courbe.Length) { print_Courbe(1, 0, courbe.Length - 1); } else { print_Courbe(1, 0, (this.Width - 10) / agrandissement); } launch.MouseClick -= Event_Launcher; }
public void Restart(double masse, double gravity, double speed, double angle, double posY0) { ctrl = true; courbe = null; Controls.Clear(); graph = buildLabel(); envi = new Environnement(gravity, speed, angle); obj_tennis = new Objets(masse, posY0); sizeFirstMenu = 1000; agrandissement = envi.Agrandissement(10, obj_tennis, graph); while (agrandissement == -1) { graph.Width = (int)(graph.Width * 2); agrandissement = envi.Agrandissement(10, obj_tennis, graph); } while (agrandissement == -2) { graph.Height = (int)(graph.Height * 1.2); agrandissement = envi.Agrandissement(10, obj_tennis, graph); } but_tennis = buttonGenerator(graph.Location.X, (int)(graph.Location.Y + (graph.Height) - agrandissement * obj_tennis.getPosY())); but_tennis.Size = new Size(10, 10); infos = buildLabel(); infos.Size = new Size((sizeFirstMenu - 20) / 3, 60); infos.Location = new Point(10, 10); infos.Text = "Mass: " + obj_tennis.getMasse() + "\nSpeed: " + envi.getVit0() + "\nAngle: " + envi.getAngle() + "\nGravity: " + envi.getGravity(); launch = buttonGenerator((20 + (sizeFirstMenu - 20) / 3), 10); launch.Text = "Launch"; restart = buttonGenerator(10 + 2 * (10 + (sizeFirstMenu - 20) / 3), 10); restart.Text = "Restart"; but_tennis.MouseClick += new MouseEventHandler(ButtonPosTraject); launch.MouseClick += new MouseEventHandler(Event_Launcher); restart.MouseClick += new MouseEventHandler(EventRestart); graph.Paint += buildAxes; graph.MouseClick += new MouseEventHandler(MousePos); this.Scroll += panel1_Scroll; this.KeyPreview = true; this.KeyDown += new KeyEventHandler(On_CTRL); this.KeyUp += new KeyEventHandler(Off_CTRL); }