コード例 #1
0
        private void btnOpenSave_Click(object sender, RoutedEventArgs e)
        {
            // Creating \Pentegames directory so there is no error
            System.IO.Directory.CreateDirectory(@"\CardGameGallery\War");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\CardGameGallery\War";
            openFileDialog.Multiselect      = true;
            openFileDialog.Filter           = "War Saves|*.War";
            //openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            if (openFileDialog.ShowDialog() == true)
            {
                try
                {
                    // Get the file path chosen by the user
                    stream = new FileStream(@$ "{openFileDialog.FileName}", FileMode.Open, FileAccess.Read);
                    // Deserializing the game save file to a GameSave object
                    WarSaveGame save = (WarSaveGame)formatter.Deserialize(stream);
                    // Opening the play window with the GameSave object
                    PlayWarWindow playWar = new PlayWarWindow(save, openFileDialog.FileName, this);
                    // Hiding main menu withle play window is up
                    Hide();
                    // Displaying the play window
                    playWar.Show();
                    // CLosing the stream to free up resources
                    stream.Close();
                }
                catch
                {
                    // If an error occurs while opening save file
                    MessageBox.Show("Something went wrong, try again.");
                }
            }
        }
コード例 #2
0
        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            Player[] players = new Player[PLAYERS];
            players[0] = new Player(txtName1.Text, false, new List <Card>(), 0);
            players[1] = new Player(txtName2.Text, (bool)p2.IsChecked, new List <Card>(), 0);
            WarSaveGame   newWar  = new WarSaveGame(players);
            PlayWarWindow playWar = new PlayWarWindow(newWar, this);

            Hide();
            playWar.Show();
        }