Exemplo n.º 1
0
        private void saveJsonSerialization(Stream saveStream)
        {
            var info = new allInformations();

            info.title       = puzzleTitleTextBox.Text;
            info.difficulty  = difficultyTextBox.Text;
            info.columnCount = columns;
            info.rowCount    = rows;
            info.isColored   = new bool[columns * rows];
            for (int i = 0; i < columns; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    if (bgColors[i, j] == Color.Black)
                    {
                        info.isColored[i * rows + j] = true;
                    }
                }
            }

            string       serialization = JsonSerializer.Serialize <allInformations>(info);
            StreamWriter sw            = new StreamWriter(saveStream);

            sw.Write(serialization);
            sw.Close();
        }
Exemplo n.º 2
0
        private void iterateFiles()
        {
            Stream loadStream;

            listView.Items.Clear();
            fileCount = 0;
            var info = new allInformations();

            listInfo = new List <allInformations>();

            foreach (var file in Directory.EnumerateFiles(directoryTextBox.Text))
            {
                if (file.ToString().EndsWith(".json"))
                {
                    loadStream = File.OpenRead(file);
                    if (loadJsonSerialization(loadStream, ref info))
                    {
                        listInfo.Add(info);
                        fileCount++;
                    }
                }
            }

            for (int i = 0; i < fileCount; i++)
            {
                listView.Items.Add(new ListViewItem(new[] { listInfo[i].title, listInfo[i].columnCount.ToString(),
                                                            listInfo[i].rowCount.ToString(), listInfo[i].difficulty }));
            }
            listView.Refresh();
        }
Exemplo n.º 3
0
        private bool loadJsonSerialization(Stream loadStream, ref allInformations info)
        {
            StreamReader sr            = new StreamReader(loadStream);
            string       serialization = sr.ReadToEnd();

            info = JsonSerializer.Deserialize <allInformations>(serialization);
            sr.Close();
            if (info.columnCount < 2 || info.columnCount > 15 || info.rowCount < 2 || info.rowCount > 15 ||
                info.title == null || info.difficulty == null || info.isColored.Length != info.columnCount * info.rowCount)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 4
0
        private bool loadJsonSerialization(Stream loadStream)
        {
            StreamReader    sr            = new StreamReader(loadStream);
            string          serialization = sr.ReadToEnd();
            allInformations info          = JsonSerializer.Deserialize <allInformations>(serialization);

            if (info.columnCount < 2 || info.columnCount > 15 || info.rowCount < 2 || info.rowCount > 15 ||
                info.title == null || info.difficulty == null || info.isColored.Length != info.columnCount * info.rowCount)
            {
                var invalidForm = new InvalidFileForm();
                invalidForm.ShowDialog();
                sr.Close();
                return(false);
            }

            insertValues(info);
            sr.Close();
            return(true);
        }
Exemplo n.º 5
0
 public void insertValues(allInformations info)
 {
     this.columns = info.columnCount;
     this.rows    = info.rowCount;
     this.setColors();
     this.isColored     = new bool[info.columnCount, info.rowCount];
     this.coloredAmount = 0;
     for (int i = 0; i < info.columnCount; i++)
     {
         for (int j = 0; j < info.rowCount; j++)
         {
             this.isColored[i, j] = info.isColored[i * info.rowCount + j];
             if (this.isColored[i, j])
             {
                 this.coloredAmount++;
             }
         }
     }
 }