コード例 #1
0
        // 해당 방향에 해당하는 모든 퍼즐을 찾음.
        void AllPuzzleFindCheckDir(TotalCheckResultModel totalCheckResultModel, PuzzleModel puzzleModel,
                                   CheckDirectionTypes checkDirectionTypes, CheckDirectionTypes otherCheckDirectionTypes)
        {
            var foundedPuzzles = new List <PuzzleModel> ();

            GetFoundedPuzzles(checkDirectionTypes);
            GetFoundedPuzzles(otherCheckDirectionTypes);
            totalCheckResultModel.AddRangeMatchPuzzle(foundedPuzzles);

            void GetFoundedPuzzles(CheckDirectionTypes checkDir)
            {
                var position = GetPositionByDirectionType(puzzleModel, checkDir);

                while (ExistLineModel(position))
                {
                    if (!ContainLineModel(position))
                    {
                        position = GetPositionByDirectionType(position, checkDir);
                        continue;
                    }

                    var foundPuzzle = GetContainPuzzleModel(position);
                    if (foundPuzzle == null)
                    {
                        continue;
                    }

                    foundedPuzzles.Add(foundPuzzle);
                    position = GetPositionByDirectionType(foundPuzzle, checkDir);
                }
            }
        }
コード例 #2
0
 public void AddCheckResult(TotalCheckResultModel checkResultModel)
 {
     checkResultModels.Add(checkResultModel);
     checkResultModels = checkResultModels.OrderByDescending(x => x.CheckPuzzles.Count).ToList();
 }
コード例 #3
0
        /// <summary>
        /// 특수 퍼즐 영역에 맞는 퍼즐들을 찾음.
        /// </summary>
        private void ProcessSpecialPuzzle(TotalCheckResultModel totalCheckResultModel, PuzzleModel puzzleModel)
        {
            if (totalCheckResultModel.PuzzleMatchingTypes == PuzzleMatchingTypes.Pick)
            {
                var targetPuzzleColorTypes =
                    totalCheckResultModel.PickedPuzzle?.PuzzleColorTypes ?? GetRandomPuzzleColorTypes();

                if (_playerControlModel.IsPlayerControl)
                {
                    var foundedPuzzles = new List <PuzzleModel> ();

                    switch (totalCheckResultModel.PickedPuzzle?.PuzzleSpecialTypes)
                    {
                    case PuzzleSpecialTypes.None:
                        foundedPuzzles = GetPuzzles(x => x.PuzzleColorTypes.Equals(targetPuzzleColorTypes))
                                         .ToList();
                        break;

                    case PuzzleSpecialTypes.ToVertical:
                    case PuzzleSpecialTypes.ToUpLeftDownRight:
                    case PuzzleSpecialTypes.ToUpRightDownLeft:
                        foundedPuzzles = GetPuzzles(x => x.PuzzleColorTypes.Equals(targetPuzzleColorTypes))
                                         .ToList();
                        foundedPuzzles.Foreach(x => x.ChangeSpecialPuzzle(GetRandomLineSpecialTypes()));
                        break;

                    case PuzzleSpecialTypes.Bomb:
                        foundedPuzzles = GetPuzzles(x => x.PuzzleColorTypes.Equals(targetPuzzleColorTypes))
                                         .ToList();
                        foundedPuzzles.Foreach(x => x.ChangeSpecialPuzzle(PuzzleSpecialTypes.Bomb));
                        break;

                    case PuzzleSpecialTypes.PickColors:
                        foundedPuzzles = AllPuzzleModels.ToList();
                        break;
                    }

                    totalCheckResultModel.AddRangeMatchPuzzle(foundedPuzzles);
                }

                IEnumerable <PuzzleModel> GetPuzzles(Func <PuzzleModel, bool> predicate = null)
                {
                    return(AllPuzzleModels.Where(predicate));
                }

                PuzzleSpecialTypes GetRandomLineSpecialTypes()
                {
                    var rand = Random.Range(0, (int)PuzzleSpecialTypes.ToUpRightDownLeft);

                    return((PuzzleSpecialTypes)rand);
                }
            }

            switch (puzzleModel.PuzzleSpecialTypes)
            {
            case PuzzleSpecialTypes.ToVertical:
                totalCheckResultModel.AddRangeMatchPuzzle(AllPuzzleModels.Where(x =>
                                                                                x.Column == puzzleModel.Column));
                break;

            case PuzzleSpecialTypes.ToUpLeftDownRight:
                AllPuzzleFindCheckDir(totalCheckResultModel, puzzleModel, CheckDirectionTypes.ToUpLeft,
                                      CheckDirectionTypes.ToDownRight);
                break;

            case PuzzleSpecialTypes.ToUpRightDownLeft:
                AllPuzzleFindCheckDir(totalCheckResultModel, puzzleModel, CheckDirectionTypes.ToUpRight,
                                      CheckDirectionTypes.ToDownLeft);
                break;

            case PuzzleSpecialTypes.Bomb:
                var aroundPositions = GetAroundPositionModel(puzzleModel.PositionModel);
                totalCheckResultModel.AddRangeMatchPuzzle(aroundPositions.Select(GetContainPuzzleModel));
                break;

            case PuzzleSpecialTypes.PickColors:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #4
0
        /// <summary>
        /// 움직인 퍼즐이 조합 가능한 퍼즐인지 체크.
        /// </summary>
        /// <returns></returns>
        private void CheckCombinablePuzzle()
        {
            if (!_playerControlModel.IsPlayerControl)
            {
                return;
            }

            // 이동시킨 퍼즐 둘 다 특수 퍼즐일 경우.
            if (_playerControlModel.Origin.PuzzleSpecialTypes != PuzzleSpecialTypes.None &&
                _playerControlModel.Target.PuzzleSpecialTypes != PuzzleSpecialTypes.None)
            {
                CombineSpecialTypePuzzle();
                _matchingResultModel.SetMathingState(true);
                return;
            }

            // 둘 다 특수 퍼즐이 아니어도 Pick타입의 퍼즐은 확인함.
            CombinePickTypePuzzle();

            void CombineSpecialTypePuzzle()
            {
                var checkResult = new TotalCheckResultModel();

                checkResult.SetMatchingType(PuzzleMatchingTypes.CombineSpecial);
                checkResult.AddRangeMatchPuzzle(new[]
                {
                    _playerControlModel.Origin,
                    _playerControlModel.Target
                });
                _matchingResultModel.AddCheckResult(checkResult);
            }

            void CombinePickTypePuzzle()
            {
                var isOriginPickType = _playerControlModel.Origin.PuzzleSpecialTypes == PuzzleSpecialTypes.PickColors;
                var isTargetPickType = _playerControlModel.Target.PuzzleSpecialTypes == PuzzleSpecialTypes.PickColors;

                if (!isOriginPickType && !isTargetPickType)
                {
                    return;
                }

                var checkResult = new TotalCheckResultModel();

                _matchingResultModel.SetMathingState(true);

                if (isOriginPickType && isTargetPickType)
                {
                    SetPickState(_playerControlModel.Origin, _playerControlModel.Target);
                    return;
                }

                if (isOriginPickType)
                {
                    SetPickState(_playerControlModel.Origin, _playerControlModel.Target);
                    return;
                }

                SetPickState(_playerControlModel.Target, _playerControlModel.Origin);

                void SetPickState(PuzzleModel specialPuzzle, PuzzleModel pickedPuzzle)
                {
                    checkResult.AddCheckedPuzzle(specialPuzzle);
                    checkResult.SetPickedPuzzle(pickedPuzzle);
                    checkResult.SetMatchingType(PuzzleMatchingTypes.Pick);
                    _matchingResultModel.AddCheckResult(checkResult);
                }
            }
        }