private void newGameButton_Click(object sender, EventArgs e) { this.Enabled = false; using (NewGameDialog dlg = new NewGameDialog()) { if (dlg.ShowDialog() == DialogResult.OK) { int playersCount = dlg.playersCount; float money = dlg.millions; using (PlayersChoosing dlg2 = new PlayersChoosing(playersCount, money)) { if (dlg2.ShowDialog() == DialogResult.OK) { players = dlg2.players; Hide(); using (Monopoly gw = new Monopoly(players)) { Game g = new Game(players, gw); if (gw.ShowDialog() == DialogResult.OK) { Show(); } }; } } } } this.Enabled = true; }
private void loadGameButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog { AddExtension = true, DefaultExt = "mon", CheckPathExists = true, //sfd.FileName = "game.mon"; Filter = "Monopoly saved games (*.mon)|*.mon", InitialDirectory = AppDomain.CurrentDomain.BaseDirectory, Title = "Choose a game to load", ValidateNames = true }; if (ofd.ShowDialog() == DialogResult.OK) { if (File.Exists(ofd.FileName)) { Game g; try { Stream openFileStream = File.OpenRead(ofd.FileName); BinaryFormatter deserializer = new BinaryFormatter(); g = (Game)deserializer.Deserialize(openFileStream); openFileStream.Close(); Hide(); using (Monopoly gw = new Monopoly(g.GetPlayers())) { gw.Show(); g.SetWindow(gw); g.UpdateWindow(); gw.Hide(); if (gw.ShowDialog() == DialogResult.OK) { Show(); } }; } catch (IOException ex) { Console.WriteLine(ex.StackTrace); MessageBox.Show("Failed to load game."); } } } }