Ejemplo n.º 1
0
        private void createCrozzleColumns(WordDataList wordDataList)
        {
            // Create a List to store String arrays, one String[] for each column, one String for each letter.
            CrozzleColumns = new List <String[]>();

            // Create and store empty columns into the list.
            for (int i = 0; i < Columns; i++)
            {
                String[] column = new String[Rows];
                for (int j = 0; j < column.Length; j++)
                {
                    column[j] = " ";
                }
                CrozzleColumns.Add(column);
            }

            // Store VERTICAL words into the columns.
            foreach (WordData vWordData in wordDataList.VerticalWordData)
            {
                if (vWordData.Location.Row >= 1 && vWordData.Location.Row <= Rows &&
                    vWordData.Location.Column >= 1 && vWordData.Location.Column <= Columns)
                {
                    // Store each letter into the approriate column.
                    String[] column = CrozzleColumns[vWordData.Location.Column - 1];
                    int      row    = vWordData.Location.Row - 1;
                    foreach (Char c in vWordData.Letters)
                    {
                        if (row < Rows)
                        {
                            column[row++] = new String(c, 1);
                        }
                    }
                }
            }

            // Store HORIZONTAL words into the columns.
            foreach (WordData hWordData in wordDataList.HorizontalWordData)
            {
                if (hWordData.Location.Row >= 1 && hWordData.Location.Row <= Rows &&
                    hWordData.Location.Column >= 1 && hWordData.Location.Column <= Columns)
                {
                    // Store each letter into the ith column, but the same row location.
                    int i = hWordData.Location.Column - 1;
                    foreach (Char c in hWordData.Letters)
                    {
                        if (i < Columns)
                        {
                            String[] column = CrozzleColumns[i];
                            column[hWordData.Location.Row - 1] = new String(c, 1);
                            i++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //create crozzle grid
        private void createCrozzleRows(WordDataList wordDataList)
        {
            // Create a List to store String arrays, one String[] for each row, one String for each letter.
            CrozzleRows = new List <String[]>();

            // Create and store empty rows into the list.
            for (int i = 0; i < Rows; i++)
            {
                String[] row = new String[Columns];
                for (int j = 0; j < row.Length; j++)
                {
                    row[j] = " ";
                }
                CrozzleRows.Add(row);
            }

            // Store HORIZONTAL words into the rows.
            foreach (WordData hWordData in wordDataList.HorizontalWordData)
            {
                if (hWordData.Location.Row >= 1 && hWordData.Location.Row <= Rows &&
                    hWordData.Location.Column >= 1 && hWordData.Location.Column <= Columns)
                {
                    // Store each letter into the approriate row.
                    String[] row = CrozzleRows[hWordData.Location.Row - 1];
                    int      col = hWordData.Location.Column - 1;
                    foreach (Char c in hWordData.Letters)
                    {
                        if (col < Columns)
                        {
                            row[col++] = new String(c, 1);
                        }
                    }
                }
            }

            // Store VERTICAL words into the rows.
            foreach (WordData vWordData in wordDataList.VerticalWordData)
            {
                if (vWordData.Location.Row >= 1 && vWordData.Location.Row <= Rows &&
                    vWordData.Location.Column >= 1 && vWordData.Location.Column <= Columns)
                {
                    // Store each letter into the ith row, but the same column location.
                    int i = vWordData.Location.Row - 1;
                    foreach (Char c in vWordData.Letters)
                    {
                        if (i < Rows)
                        {
                            String[] row = CrozzleRows[i];
                            row[vWordData.Location.Column - 1] = new String(c, 1);
                            i++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static Boolean TryParse(List <String> originalWordDataList, Crozzle aCrozzle, out WordDataList aWordDataList)
        {
            List <WordData> aList = new List <WordData>();

            Errors        = new List <String>();
            aWordDataList = new WordDataList(originalWordDataList);

            foreach (String line in originalWordDataList)
            {
                WordData aWordData;
                if (WordData.TryParse(line, aCrozzle, out aWordData))
                {
                    aWordDataList.Add(aWordData);
                }
                else
                {
                    Errors.AddRange(WordData.Errors);
                }
            }

            aWordDataList.Valid = Errors.Count == 0;
            return(aWordDataList.Valid);
        }
Ejemplo n.º 4
0
        public static Boolean TryParse(String path, Configuration aConfiguration, WordList wordList, out Crozzle aCrozzle)
        {
            Errors   = new List <String>();
            aCrozzle = new Crozzle(path, aConfiguration, wordList);

            // Open file.
            StreamReader  fileIn   = new StreamReader(path);
            List <String> wordData = new List <string>();

            // Validate file.
            while (!fileIn.EndOfStream)
            {
                // Read a line.
                String line = fileIn.ReadLine();

                // Parse a crozzle file item.
                CrozzleFileItem aCrozzleFileItem;
                if (CrozzleFileItem.TryParse(line, out aCrozzleFileItem))
                {
                    if (aCrozzleFileItem.IsConfigurationFile)
                    {
                        // Get the configuration file name.
                        String configurationPath = aCrozzleFileItem.KeyValue.Value;
                        if (configurationPath == null)
                        {
                            Errors.Add(CrozzleFileErrors.ConfigurationFilenameMissing);
                        }
                        else
                        {
                            configurationPath = configurationPath.Trim();
                            if (Validator.IsDelimited(configurationPath, StringDelimiters))
                            {
                                configurationPath = configurationPath.Trim(StringDelimiters);
                            }

                            if (!Path.IsPathRooted(configurationPath))
                            {
                                String directoryName = Path.GetDirectoryName(path);
                                configurationPath = directoryName + @"\" + configurationPath;
                            }

                            aCrozzle.ConfigurationPath = configurationPath;
                        }
                    }
                    else if (aCrozzleFileItem.IsWordListFile)
                    {
                        // Get the word list file name.
                        String wordListPath = aCrozzleFileItem.KeyValue.Value;
                        if (wordListPath == null)
                        {
                            Errors.Add(CrozzleFileErrors.WordlistFilenameMissing);
                        }
                        else
                        {
                            wordListPath = wordListPath.Trim();
                            if (Validator.IsDelimited(wordListPath, StringDelimiters))
                            {
                                wordListPath = wordListPath.Trim(StringDelimiters);
                            }

                            if (!Path.IsPathRooted(wordListPath))
                            {
                                String directoryName = Path.GetDirectoryName(path);
                                wordListPath = directoryName + @"\" + wordListPath;
                            }

                            aCrozzle.WordListPath = wordListPath;
                        }
                    }
                    else if (aCrozzleFileItem.IsRows)
                    {
                        // Get the number of rows.
                        int rows;
                        if (Validator.IsInt32(aCrozzleFileItem.KeyValue.Value.Trim(), out rows))
                        {
                            aCrozzle.Rows = rows;
                        }
                        else
                        {
                            Errors.Add(String.Format(CrozzleFileErrors.RowError, aCrozzleFileItem.KeyValue.OriginalKeyValue, Validator.Errors[0]));
                        }
                    }
                    else if (aCrozzleFileItem.IsColumns)
                    {
                        // Get the number of columns.
                        int columns;
                        if (Validator.IsInt32(aCrozzleFileItem.KeyValue.Value.Trim(), out columns))
                        {
                            aCrozzle.Columns = columns;
                        }
                        else
                        {
                            Errors.Add(String.Format(CrozzleFileErrors.ColumnError, aCrozzleFileItem.KeyValue.OriginalKeyValue, Validator.Errors[0]));
                        }
                    }
                    else if (aCrozzleFileItem.IsRow)
                    {
                        // Collect potential word data for a horizontal word.
                        wordData.Add(aCrozzleFileItem.KeyValue.OriginalKeyValue);
                    }
                    else if (aCrozzleFileItem.IsColumn)
                    {
                        // Collect potential word data for a vertical word.
                        wordData.Add(aCrozzleFileItem.KeyValue.OriginalKeyValue);
                    }
                }
                else
                {
                    Errors.AddRange(CrozzleFileItem.Errors);
                }
            }

            // Close files.
            fileIn.Close();


            // Get potential word data list.
            WordDataList wordDataList;

            if (!WordDataList.TryParse(wordData, aCrozzle, out wordDataList))
            {
                Errors.AddRange(WordDataList.Errors);
            }
            aCrozzle.WordDataList = wordDataList;


            // Validate file sections.
            // Check the configuration file name.
            if (aCrozzle.Configuration != null)
            {
                if (aCrozzle.Configuration.ConfigurationPath != aCrozzle.ConfigurationPath)
                {
                    Errors.Add(String.Format(CrozzleFileErrors.ConfigurationFilenameError, aCrozzle.ConfigurationPath, aCrozzle.Configuration.ConfigurationFileName));
                }
            }

            // Check the word list file name.
            if (aCrozzle.WordList != null)
            {
                if (aCrozzle.WordList.WordlistPath != aCrozzle.WordListPath)
                {
                    Errors.Add(String.Format(CrozzleFileErrors.WordlistFilenameError, aCrozzle.WordListPath, aCrozzle.WordList.WordlistFileName));
                }
            }

            // Raw word data of horizontal and vertical words were obtained when reading the crozzle file,
            // but now we need to create crozzle rows and crozzle columns that represent the crozzle.
            aCrozzle.createCrozzleRows(aCrozzle.WordDataList);
            aCrozzle.createCrozzleColumns(aCrozzle.WordDataList);

            // Store validity.
            aCrozzle.FileValid = Errors.Count == 0;
            return(aCrozzle.FileValid);
        }