Ejemplo n.º 1
0
        /// <summary>
        /// 해당 방향에 있는 바로 옆 퍼즐의 키 값을 리턴.
        /// </summary>
        public PositionModel GetKeyByAngle(PositionModel positionModel, float angle)
        {
            if (!AllLineModels.ContainsKey(positionModel.Column))
            {
                return(PositionModel.EmptyPositionModel);
            }

            // To upper direction.
            if (Enumerable.Range(150, 60).Contains((int)angle))
            {
                return(new PositionModel(positionModel.Column, positionModel.Row + 1));
            }

            // To upper right direction.
            if (Enumerable.Range(210, 60).Contains((int)angle))
            {
                return(GetPuzzlePosition(false));
            }

            // To lower right direction.
            if (Enumerable.Range(270, 60).Contains((int)angle))
            {
                return(GetPuzzlePosition(false, false));
            }

            // To upper left direction.
            if (Enumerable.Range(90, 60).Contains((int)angle))
            {
                return(GetPuzzlePosition());
            }

            // To lower left direction.
            if (Enumerable.Range(30, 60).Contains((int)angle))
            {
                return(GetPuzzlePosition(toUpper: false));
            }

            // To lower direction.
            return(new PositionModel(positionModel.Column, positionModel.Row - 1));

            PositionModel GetPuzzlePosition(bool toLeft = true, bool toUpper = true)
            {
                var checkColumn = positionModel.Column + (toLeft ? -1 : 1);

                if (!AllLineModels.ContainsKey(checkColumn))
                {
                    return(PositionModel.EmptyPositionModel);
                }

                var anEvenNumberColumn = positionModel.Column % 2 == 0;
                var posCoeff           = anEvenNumberColumn && toUpper ? 0 : anEvenNumberColumn ? -1 : toUpper ? 1 : 0;

                return(new PositionModel(checkColumn, positionModel.Row + posCoeff));
            }
        }
Ejemplo n.º 2
0
 public bool ContainLineModel(PositionModel positionModel)
 {
     return(AllLineModels.ContainsKey(positionModel.Column) &&
            AllLineModels[positionModel.Column].ContainRow(positionModel.Row));
 }