Esempio n. 1
0
        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");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Funkce pridavajici tah jako xml element
 /// </summary>
 /// <param name="writer">XML writer</param>
 /// <param name="move">Instance tridy Move reprezentujici tah</param>
 private void addMove(XmlWriter writer, Move move)
 {
     writer.WriteStartElement("MOVE");
     writer.WriteElementString("FROM", move.From);
     writer.WriteElementString("TO", move.To);
     writer.WriteElementString("PLAYER", move.Player);
     writer.WriteEndElement();
 }