private void mainMenuOpen_Click(object sender, EventArgs e) { OpenFileDialog sDlg = new OpenFileDialog(); if (sDlg.ShowDialog() == DialogResult.OK) { string fileName = sDlg.FileName; FileStream fs = new FileStream(fileName, FileMode.Open); //XmlSerializer xs = new XmlSerializer(typeof(ModelGalaxy)); //xs.Serialize(fs, galaxy); BinaryFormatter bf = new BinaryFormatter(); galaxy = (ModelGalaxy)bf.Deserialize(fs); fs.Close(); Redraw(); } }
private void mainMenuNew_Click(object sender, EventArgs e) { Form_NewGameDialog nd = new Form_NewGameDialog(); if (nd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { galaxy = new ModelGalaxy(); galaxy.name = "Млечный путь"; switch (nd.getGalaxyType()) { case 0: generate_spiral_galaxy(true, nd.getGalaxySize(), nd.getStarsCount()); generate_spiral_galaxy(false, nd.getGalaxySize(), nd.getStarsCount()); break; case 1: generate_elliptical_galaxy(true, nd.getGalaxySize(), nd.getStarsCount()); generate_elliptical_galaxy(false, nd.getGalaxySize(), nd.getStarsCount()); break; case 2: generate_irregular_galaxy(true, nd.getGalaxySize(), nd.getStarsCount()); break; case 3: generate_sphere_galaxy(true, nd.getGalaxySize(), nd.getStarsCount()); break; } if (nd.getGalaxyRandomEvents() == true) { generate_random_events(); } Redraw(); } #region someoldcode /* * Random r = new Random(); * * for (int i = 0; i < 100; i++) * { * * StarSystem s = new StarSystem(); * s.name = "Солнце_" + i.ToString(); * s.type = 1; * s.x = 200.0 - 400.0 * r.NextDouble(); * s.y = 200.0 - 400.0 * r.NextDouble(); * s.z = 200.0 - 400.0 * r.NextDouble(); * * galaxy.stars.Add(s); * } * */ /* * galaxy = new ModelGalaxy(); * galaxy.name = "Млечный путь"; * * StarSystem s = new StarSystem(); * s.name = "Солнце"; * s.type = 1; * s.x = 50.0; * s.y = 50.0; * s.z = 50.0; * * galaxy.stars.Add(s); * * s = new StarSystem(); * s.name = "Альфа Центавра"; * s.type = 1; * s.x = 50.0; * s.y = 50.0; * s.z = -50.0; * * galaxy.stars.Add(s); * * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = 50.0; * s.y = -50.0; * s.z = 50.0; * * galaxy.stars.Add(s); * * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = -50.0; * s.y = 50.0; * s.z = 50.0; * galaxy.stars.Add(s); * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = -50.0; * s.y = -50.0; * s.z = 50.0; * galaxy.stars.Add(s); * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = -50.0; * s.y = 50.0; * s.z = -50.0; * galaxy.stars.Add(s); * * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = 50.0; * s.y = -50.0; * s.z = -50.0; * galaxy.stars.Add(s); * * s = new StarSystem(); * s.name = "Бетельгейзе"; * s.type = 1; * s.x = -50.0; * s.y = -50.0; * s.z = -50.0; * galaxy.stars.Add(s); * * StarWarp w = new StarWarp(); * w.name = "warp1"; * w.type = 1; * w.system1 = galaxy.stars[0]; * w.system2 = galaxy.stars[2]; * * galaxy.lanes.Add(w); */ #endregion }