コード例 #1
0
        private void ChoosePuzzleHandler(object sender, EventArgs e)
        {
            ChoosePuzzle chPuzzle = new ChoosePuzzle();
            DialogResult result   = chPuzzle.ShowDialog();

            if (result == DialogResult.OK)
            {
                SerializePuzzleClass spc = chPuzzle.selectedPuzzle;
                gameMode = GameMode.PlayMode;

                n      = spc.Height;
                m      = spc.Width;
                WinSeq = new FieldStat[n, m];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < spc.wseq[i].Length; j++)
                    {
                        WinSeq[i, spc.wseq[i][j]] = FieldStat.Filled;
                    }
                }
                Point centre = new Point(this.Width / 2, this.Height / 2);
                CreateLayoutPanel(centre);
                CreateButtons();
                CreateLebels(centre);
            }
        }
コード例 #2
0
        private void LoadPuzzleHandler(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = "XML files (*.xml)|*.xml";
            fileDialog.RestoreDirectory = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStream           fs  = new FileStream(fileDialog.FileName, FileMode.Open);
                XmlSerializer        xs  = new XmlSerializer(typeof(SerializePuzzleClass));
                SerializePuzzleClass spc = (SerializePuzzleClass)xs.Deserialize(fs);
                fs.Close();
                gameMode = GameMode.PlayMode;
                n        = spc.Height;
                m        = spc.Width;
                WinSeq   = new FieldStat[n, m];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < spc.wseq[i].Length; j++)
                    {
                        WinSeq[i, spc.wseq[i][j]] = FieldStat.Filled;
                    }
                }
                Point centre = new Point(this.Width / 2, this.Height / 2);
                CreateLayoutPanel(centre);
                CreateButtons();
                CreateLebels(centre);
            }
        }
コード例 #3
0
 private void loadPuzzle_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in listView1.SelectedItems)
     {
         foreach (var puzzle in PuzzlesList)
         {
             if (item.Text == puzzle.Title)
             {
                 selectedPuzzle = puzzle;
                 DialogResult   = DialogResult.OK;
                 Close();
             }
         }
     }
 }
コード例 #4
0
        private void Refresh_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0)
            {
                listView1.Items.Clear();
                foreach (string fpath in Directory.GetFiles(textBox1.Text, "*.xml"))
                {
                    FileStream           fs  = new FileStream(fpath, FileMode.Open);
                    XmlSerializer        xs  = new XmlSerializer(typeof(SerializePuzzleClass));
                    SerializePuzzleClass spc = (SerializePuzzleClass)xs.Deserialize(fs);
                    fs.Close();

                    PuzzlesList.Add(spc);

                    ListViewItem newItem = new ListViewItem(new[] { spc.Title, spc.Width.ToString(), spc.Height.ToString(), spc.Difficulty });
                    listView1.Items.Add(newItem);
                }
            }
        }
コード例 #5
0
        private void ChooseDirectory_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowser = new FolderBrowserDialog();

            if (folderBrowser.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowser.SelectedPath;
                if (textBox1.Text.Length != 0)
                {
                    foreach (string fpath in Directory.GetFiles(textBox1.Text, "*.xml"))
                    {
                        FileStream           fs  = new FileStream(fpath, FileMode.Open);
                        XmlSerializer        xs  = new XmlSerializer(typeof(SerializePuzzleClass));
                        SerializePuzzleClass spc = (SerializePuzzleClass)xs.Deserialize(fs);
                        fs.Close();

                        PuzzlesList.Add(spc);

                        ListViewItem newItem = new ListViewItem(new[] { spc.Title, spc.Width.ToString(), spc.Height.ToString(), spc.Difficulty });
                        listView1.Items.Add(newItem);
                    }
                }
            }
        }
コード例 #6
0
        private void SaveButtonClick(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Filter = "XML files (*.xml)|*.xml";

            saveFile.RestoreDirectory = true;

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                // xml serialization of array of points
                SerializePuzzleClass serializePuzzle = new SerializePuzzleClass();
                serializePuzzle.Difficulty = diff.Text;
                serializePuzzle.Height     = n;
                serializePuzzle.Width      = m;
                serializePuzzle.Title      = title.Text;
                serializePuzzle.wseq       = new int[n][];
                List <int> list = new List <int>();
                for (int i = 0; i < n; i++)
                {
                    list.Clear();
                    for (int j = 0; j < m; j++)
                    {
                        if (fieldstat[i, j] == FieldStat.Filled)
                        {
                            list.Add(j);
                        }
                    }
                    serializePuzzle.wseq[i] = list.ToArray();
                }
                var           fs = new FileStream(saveFile.FileName, FileMode.Create);
                XmlSerializer xs = new XmlSerializer(typeof(SerializePuzzleClass));
                xs.Serialize(fs, serializePuzzle);
                fs.Close();
            }
        }