Пример #1
0
        private List <string> GetIntersections(CrosswordPositionAndOrientation posAndOri)
        {
            List <string> toReturn = new List <string>();
            bool          canMove  = true;
            int           iterator = 0;

            while (canMove)
            {
                string character = EMPTY_SLOT_CHARACTER;

                int row    = posAndOri.orientation == CrosswordOrientation.VERTICAL ? posAndOri.position.row + iterator : posAndOri.position.row;
                int column = posAndOri.orientation == CrosswordOrientation.HORIZONTAL ? posAndOri.position.column + iterator : posAndOri.position.column;

                canMove = TileAvailable(new CrosswordPosition(row, column));
                if (!canMove)
                {
                    return(toReturn);
                }

                if (mCrossword.GetTile(new CrosswordPosition(row, column)).hasValue&& !(mCrossword.GetTile(new CrosswordPosition(row, column)) is CrosswordTileQuestionItem))
                {
                    character = mCrossword.GetTile(new CrosswordPosition(row, column)).element;
                }

                toReturn.Add(character);
                iterator++;
            }
            return(toReturn);
        }
Пример #2
0
        private void SetQuestionTile(CrosswordPosition questionPos, CrosswordPositionAndOrientation answerStartTile, Tuple <int, int> answerLessOrEqual)
        {
            var intersections     = GetIntersections(answerStartTile);
            var crossDatabaseItem = mDatabase.GetRandomItem(answerLessOrEqual.value1, answerLessOrEqual.value2, GetIntersectionTuples(intersections));

            if (crossDatabaseItem == null)
            {
                Debug.LogWarning(
                    string.Format("Impossible to find word with less than: {0} or equal: {1} characters, and with intersections: {2}",
                                  answerLessOrEqual.value1,
                                  answerLessOrEqual.value2,
                                  IntersectionToString(intersections)
                                  )
                    );
                return;
            }

            var crossItem = new CrosswordTileQuestionItem();

            crossItem.orientation = answerStartTile.orientation;
            crossItem.element     = crossDatabaseItem.question;
            crossItem.startPositionAndOrientation = answerStartTile;

            mCrossword.SetTile(questionPos, crossItem);
            SetAnswerTiles(crossItem, crossDatabaseItem, answerStartTile);
        }
Пример #3
0
        private Tuple <int, int> GetMinMaxAnswerLength(CrosswordPositionAndOrientation posAndOri)
        {
            int equal = -1;

            bool canMove = true;

            while (canMove)
            {
                var newPos = GetForwardTilePosition(posAndOri.position, posAndOri.orientation, ++equal);
                canMove = TileAvailable(newPos);
            }

            int lessThan = MathUtils.Max(equal - 3, 0);

            return(new Tuple <int, int>(lessThan, equal));
        }
Пример #4
0
        private void SetAnswerTiles(CrosswordTileQuestionItem crossQuestionTileItem, CrosswordDatabaseItem crossDatabaseItem, CrosswordPositionAndOrientation answerStartTile)
        {
            for (int i = 0; i < crossDatabaseItem.answer.Length; i++)
            {
                var newPos    = GetForwardTilePosition(answerStartTile.position, answerStartTile.orientation, i);
                var crossItem = new CrosswordTileAnswerItem();
                crossItem.orientation     = answerStartTile.orientation;
                crossItem.element         = GetCharacterAtIndex(crossDatabaseItem.answer, i).ToString();
                crossItem.questionElement = crossQuestionTileItem;

                mCrossword.SetTile(newPos, crossItem);
            }
        }