コード例 #1
0
        private void saveCrozzleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (SIT323Crozzle.CreateCrozzle.GetBestCrozzle().GetScore() == 0)
            {
                MessageBox.Show("No Crozzle Generated, please Generate a Crozzle first", "ERROR");
                return;
            }

            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter           = "czl file(*.czl) | *.czl";
            saveDialog.DefaultExt       = "czl";
            saveDialog.AddExtension     = true;
            saveDialog.RestoreDirectory = true;
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                string         savePath = saveDialog.FileName;
                FileStream     stream   = new FileStream(savePath, FileMode.Create);
                StreamWriter   writer   = new StreamWriter(stream);
                CrozzlePartial bs       = SIT323Crozzle.CreateCrozzle.GetBestCrozzle();

                writer.WriteLine("ROWS=" + PublicInfo.GetRows());
                writer.WriteLine("COLUMNS=" + PublicInfo.GetColumns());
                writer.WriteLine("CONFIGURATION_FILE=\"" + PublicInfo.GetConfig() + "\"");
                writer.WriteLine("WORDLIST_FILE=\"" + PublicInfo.GetWordlist() + "\"");
                for (int i = 0; i < bs.GetUsedWord().Count; i++)
                {
                    string s = "";
                    if (bs.GetUsedWord()[i].GetType().Equals("COLUMN"))
                    {
                        s += "COLUMN=";
                        s += bs.GetUsedWord()[i].GetColumns() - bs.GetMinWidth();
                        s += ",";
                        s += bs.GetUsedWord()[i].GetWordContent();
                        s += ",";
                        s += bs.GetUsedWord()[i].GetRows() - bs.GetMinHeight();
                    }
                    else if (bs.GetUsedWord()[i].GetType().Equals("ROW"))
                    {
                        s += "ROW=";
                        s += bs.GetUsedWord()[i].GetRows() - bs.GetMinHeight();
                        s += ",";
                        s += bs.GetUsedWord()[i].GetWordContent();
                        s += ",";
                        s += bs.GetUsedWord()[i].GetColumns() - bs.GetMinWidth();
                    }
                    writer.WriteLine(s);
                }
                writer.Close();
                stream.Close();
            }
        }