コード例 #1
0
ファイル: FriskaDama.cs プロジェクト: JakubKorcak/Rocnikac4
        private void saveGame_Click(object sender, EventArgs e)
        {
            SaveLoad sl = new SaveLoad();
            pauseGame();
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "XML soubor (*.xml)|*.xml";
            sfd.Title = "Uložení hry";

            List<Move> moves = new List<Move>();

            foreach (string item in History.Items)
            {
                List<string> values = new List<string>(item.Split(' '));
                values.RemoveAll(c => c.Equals(""));
                values.RemoveAll(c => c.Equals("->"));
                // odstranime typ tahu
                values.RemoveAt(4);
                // odstranime slovo hrac
                values.RemoveAt(1);

                string player = values[0];
                string from = values[1];
                string to = values[2];

                Move move = new Move(from, to, player);
                moves.Add(move);
            }
            try
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    sl.saveGame(moves, gb.WhitePlayer, gb.BlackPlayer, gb.StartsWhite, gb.ShowMoveHelp, sfd.FileName);
                    MessageBox.Show("Hra byla uložena");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                MessageBox.Show("Hru se nepodařilo uložit");
            }
        }
コード例 #2
0
ファイル: FriskaDama.cs プロジェクト: JakubKorcak/Rocnikac4
        private void loadGame_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "XML soubor (*.xml)|*.xml";
            ofd.Title = "Načtení uložené hry";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    cleanHistory();
                    SaveLoad sl = new SaveLoad();
                    this.gb = sl.loadGame(ofd.FileName, gb);
                    this.gb.drawBoard();
                    this.gb.colorUp();
                    pauseGame();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("Hru se nepodařilo načíst!\n{0}", ex.Message.ToString()));
                    cleanHistory();
                }
            }
            else
                MessageBox.Show("Hru se nepodařilo načíst!");
        }