Beispiel #1
0
        /// <summary>
        /// Complete loading crozzle
        /// </summary>
        public void SetLoadingComplete()
        {
            CrozzleLogger.InitLog(Name, true);

            CreateMatrix();
            FillMatrix();
            CalculateScore();
            _loaded = true;

            CrozzleLogger.EndLog(Name, true, ValidationResult.IsValid);
        }
Beispiel #2
0
        /// <summary>
        /// Fill matrix with values
        /// </summary>
        private void FillMatrix()
        {
            var allCells = Rows.SelectMany(row => row.Cells).ToList();

            foreach (var wordModelObject in DisplayedWords)
            {
                List <Cell> cells = null;

                var orientation          = wordModelObject.Orientation;
                var hPosition            = wordModelObject.HorizontalPosition;
                var vPosition            = wordModelObject.VerticalPosition;
                var orientationPostition = 0;
                var word          = wordModelObject.Word;
                var startPosition = 0;
                var endPosition   = 0;
                if (orientation == WordOrientation.Horizontal)
                {
                    startPosition        = vPosition;
                    endPosition          = vPosition + word.Length;
                    orientationPostition = hPosition;
                    cells = allCells.Where(cell => cell.ColumnIndex >= startPosition && cell.ColumnIndex < endPosition && cell.RowIndex == hPosition).ToList();
                }
                if (orientation == WordOrientation.Vertical)
                {
                    startPosition        = hPosition;
                    endPosition          = hPosition + word.Length;
                    orientationPostition = vPosition;
                    cells = allCells.Where(cell => cell.RowIndex >= startPosition && cell.RowIndex < endPosition && cell.ColumnIndex == vPosition).ToList();
                }

                for (int i = 0; i < word.Length; i++)
                {
                    var cell      = cells[i];
                    var character = word[i];
                    cell.Character = character.ToString();
                    cell.EntryCount++;
                    cell.Words.Add(wordModelObject);
                }

                var delimeted        = allCells.DelimetedBySpaces(startPosition, endPosition, orientationPostition, orientation);
                var orientationIsOk  = Constraints.WordOrientationIsCorrect(startPosition, endPosition);
                var intersectingIsOk = allCells.IntersectingConstarint(DifficultyLevel);


                if (!delimeted)
                {
                    ValidationResult.AddError($"Word {wordModelObject} has not enough spaces");
                    CrozzleLogger.Log($"Word {wordModelObject} has not enough spaces");
                }
                if (!orientationIsOk)
                {
                    ValidationResult.AddError($"Word {wordModelObject} has problem with orientation");
                    CrozzleLogger.Log($"Word {wordModelObject} has not enough spaces");
                }
                if (!intersectingIsOk)
                {
                    ValidationResult.AddError($"Words intersection count is invalid difficulty level - {DifficultyLevel}");
                    CrozzleLogger.Log($"Word {wordModelObject} has not enough spaces");
                }
            }
        }