Ejemplo n.º 1
0
        private PuzzleOrb GetOrbWithIndex(Index2D index)
        {
            if (!IsValidBoardIndex(index))
            {
                return(null);
            }

            return(Board[index.y, index.x]);
        }
Ejemplo n.º 2
0
        public bool IsValidBoardIndex(Index2D index)
        {
            if (index.x < 0 || index.x >= Board.Columns)
            {
                return(false);
            }

            if (index.y < 0 || index.y >= Board.Rows)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void SwapOrbPlaces(Index2D from, Index2D to)
        {
            if (!IsValidBoardIndex(from))
            {
                throw new System.Exception(message: "Invalid [from] board index " + from);
            }

            if (!IsValidBoardIndex(to))
            {
                throw new System.Exception(message: "Invalid [to] board index " + to);
            }

            PuzzleOrb fromOrb = Board[from.y, from.x];
            PuzzleOrb toOrb   = Board[to.y, to.x];

            fromOrb.index = to;
            toOrb.index   = from;

            Board[to.y, to.x]     = fromOrb;
            Board[from.y, from.x] = toOrb;
        }
Ejemplo n.º 4
0
        private MatchTypes GetMatchType(List <PuzzleOrb> matches)
        {
            int orbCount = matches.Count;

            if (orbCount == 3)
            {
                return(MatchTypes.Three);
            }
            else if (orbCount == 4)
            {
                return(MatchTypes.Four);
            }
            else
            {
                List <Index2D> matchIndexes = new List <Index2D>();
                for (int i = 0; i < matches.Count; i++)
                {
                    matchIndexes.Add(matches[i].index);
                }

                if (orbCount == 5)
                {
                    Index2D leftMostIndex = matchIndexes[0];
                    for (int i = 0; i < matchIndexes.Count; i++)
                    {
                        if (leftMostIndex.x > matchIndexes[i].x)
                        {
                            leftMostIndex = matchIndexes[i];
                        }
                    }

                    Index2D   crossCenter = leftMostIndex.RightIndex;
                    Index2D[] arr         = new Index2D[]
                    {
                        crossCenter,
                        crossCenter.RightIndex,
                        crossCenter.UpIndex,
                        crossCenter.DownIndex
                    };

                    bool hasIndexes = true;
                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (!matchIndexes.Contains(arr[i]))
                        {
                            hasIndexes = false;
                            break;
                        }
                    }

                    if (hasIndexes)
                    {
                        return(MatchTypes.Cross);
                    }
                }

                if (orbCount == Board.Columns || orbCount == Board.Rows)
                {
                    bool inSameRow    = true;
                    bool inSameColumn = true;
                    int  y            = matchIndexes[0].y;
                    int  x            = matchIndexes[0].x;

                    for (int j = 1; j < matchIndexes.Count; j++)
                    {
                        if (matchIndexes[j].y != y)
                        {
                            inSameRow = false;
                        }

                        if (matchIndexes[j].x != x)
                        {
                            inSameColumn = false;
                        }

                        if (!inSameColumn && !inSameRow)
                        {
                            break;
                        }
                    }

                    if (orbCount == Board.Columns && inSameRow)
                    {
                        return(MatchTypes.Row);
                    }
                    else if (orbCount == Board.Rows && inSameColumn)
                    {
                        return(MatchTypes.Column);
                    }
                    else
                    {
                        return(MatchTypes.Linked);
                    }
                }
                else
                {
                    return(MatchTypes.Linked);
                }
            }
        }