public void AddStaticBody(PointF point, float Weight, string Name) { if (!Play) { point.X += space.Beginning.X; point.Y += space.Beginning.Y; SpaceStaticBody body = new SpaceStaticBody(point, Weight, Name); space.AddBody(body); } }
private void SaveButton_Click(object sender, EventArgs e) { var bodies = form.space.AllBodies(); bool TheOnlyName = true; for (int i = 0; i < bodies.Length; i++) { if (bodies[i].Name == textBox6.Text && bodies[i] != body) { TheOnlyName = false; } } if (form.space.GetSpace().follow == body) { form.space.GetSpace().follow = null; } if (form.drawingShip == body) { form.drawingShip = null; } if (TheOnlyName) { try { body.color = colorBody; if (body.X != (float)Convert.ToDouble(textBox1.Text)) { body.X = (float)Convert.ToDouble(textBox1.Text); } if (body.Y != (float)Convert.ToDouble(textBox2.Text)) { body.Y = (float)Convert.ToDouble(textBox2.Text); } if (body.sX != (float)Convert.ToDouble(textBox4.Text)) { body.sX = (float)Convert.ToDouble(textBox4.Text); } if (body.sY != (float)Convert.ToDouble(textBox3.Text)) { body.sY = (float)Convert.ToDouble(textBox3.Text); } body.Weight = (float)Convert.ToDouble(textBox5.Text); body.Name = textBox6.Text; if (body is SpaceShip) { if (StaticCheckBox.Checked) { form.drawingShip = (SpaceShip)body; } ((SpaceShip)body).DrawShip(); } else { SpaceBody t; if (StaticCheckBox.Checked) { t = new SpaceStaticBody(body); } else { t = new SpaceBody(body); } form.space.DeleteBody(body); form.space.AddBody(t); body = t; } if (FollowCheckBox.Checked) { form.space.GetSpace().follow = body; } if (IntoOrbitOfThisBody != null) { try { form.space.Orbit(IntoOrbitOfThisBody, body, clockwise); } catch { MessageBox.Show("R == 0"); } } Close(); } catch { MessageBox.Show("Недопустимый параметр"); } } else { MessageBox.Show("Такое имя уже существует"); } }