Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (GameFileName == null)
            {
                var dlg = new OpenFileDialog();
                dlg.Filter = "Savegames (*.gam)|*.gam|All files|*.*";
                dlg.Title  = "Please select a savegame to load";
                var result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    Application.Exit();
                    return;
                }
                GameFileName = dlg.FileName;
            }

            var fname = Path.GetFileNameWithoutExtension(GameFileName);

            plrFileName = Path.Combine(Path.GetDirectoryName(GameFileName), fname) + ".plr";
            try
            {
                var splitFileName = fname.Split('_');
                gameName   = splitFileName[0];
                turnNumber = int.Parse(splitFileName[1]);
                playerName = splitFileName[2];
                Text       = string.Format("Event Horizon - {0} turn {1}", gameName, turnNumber, playerName);
            }
            catch
            {
                Text = "Event Horizon";
            }
            try
            {
                var doc   = XDocument.Load(GameFileName);
                var root  = doc.Root;
                var shelf = NounCollection.FromXml(root);
                Library.NounLibrary.Add(shelf);


                // TODO - try to load commands from existing plr file?

                universe     = Universe.Load(shelf["Vroot"]);
                map.Universe = universe;
                LoadEvents();
                dgvShips.AutoGenerateColumns = false;
                selectedShips = new List <Ship>();


                foreach (var sector in universe.Sectors)
                {
                    foreach (var ship in sector.Ships)
                    {
                        var bmp = new Bitmap(128, 128);
                        var g   = Graphics.FromImage(bmp);
                        g.Clear(Color.Black);
                        ilShipsBig.Images.Add(ship.ID, bmp);

                        ilShipsSmall.Images.Add(ship.ID, bmp);
                    }
                }

                map.HighlightedShips = universe.Sectors.SelectMany(s => s.Ships);

                dgvIncome.AutoGenerateColumns = false;
                dgvIncome.DataSource          = universe.IncomeSectors.ToArray();

                dgvConstruction.AutoGenerateColumns = false;
                foreach (var design in universe.Designs)
                {
                    colDesign.Items.Add(design.Name);
                }
                bsConstruction.DataSource  = universe.Construction;
                dgvConstruction.DataSource = bsConstruction;

                UpdateTreasury();

                dgvBattles.AutoGenerateColumns = false;
                dgvBattles.DataSource          = universe.Battles;

                dgvEmpires.AutoGenerateColumns = false;
                foreach (var dir in Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Shipsets")).Select(dir => Path.GetFileName(dir)).Union(universe.Players.Select(p => p.ShipsetName)))
                {
                    colShipset.Items.Add(dir);
                }
                dgvEmpires.DataSource = universe.Players.ToArray();
                allShips = SortShipsDefault(universe.Ships).ToArray();
            }
            catch (System.Xml.XmlException ex)
            {
                MessageBox.Show(GameFileName + "\nis not a valid Event Horizon savegame.");
                Application.Exit();
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show($"{GameFileName} does not exist.");
                Application.Exit();
            }
            catch (DirectoryNotFoundException ex)
            {
                MessageBox.Show($"{GameFileName} does not exist.");
                Application.Exit();
            }
            // load settings
            Settings.Default.Reload();

            // start music if we have any audio devices to play on
            Music.CurrentMood = Mood.Strategic;

            // TODO - make a settings dialog!
            Settings.Default.Save();
        }
Exemple #2
0
 internal Player(Universe universe)
 {
     Universe = universe;
 }