Exemple #1
0
        private void RegisterCellWithSection(SectionCollection sectionCollection, FieldSectionType sectionType, SudokuCell cell)
        {
            RegistrationKey sectionKey = null;

            switch (sectionType)
            {
            case FieldSectionType.Row:
                sectionKey = CreateRowKey(cell);
                break;

            case FieldSectionType.Column:
                sectionKey = CreateColumnKey(cell);
                break;

            case FieldSectionType.Block:
                sectionKey = CreateBlockKey(cell);
                break;

            default:
                throw new Exception("No fieldtype is set");
            }

            //retrieve the section from the collection
            SilverSudokuSection theSection = sectionCollection.GetSectionByKey(sectionKey);

            if (theSection == null)
            {   //the section doesn't exist: create it and add it to the collection
                theSection             = new SilverSudokuSection(NumColumns, sectionKey);
                theSection.SectionType = sectionType;
                sectionCollection.Add(theSection);
            }
            theSection.RegisterCell(cell);
            cell.Parents.Add(theSection);
        }
Exemple #2
0
        /// <summary>
        /// Retrieves a section by a key.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public SilverSudokuSection GetSectionByKey(RegistrationKey key)
        {
            SilverSudokuSection retValue = null;

            foreach (SilverSudokuSection section in sections)
            {
                if (section.Key.Equals(key))
                {
                    retValue = section;
                }
            }
            return(retValue);
        }
Exemple #3
0
 public void Add(SilverSudokuSection section)
 {
     sections.Add(section);
 }