Exemple #1
0
        public void MoveMatchedOrbsToTheTop()
        {
            List <PuzzleOrb> matched = GetAllMatchedOrbs();

            for (int y = 0; y < Board.Rows; y++)
            {
                for (int x = 0; x < Board.Columns; x++)
                {
                    PuzzleOrb it = GetOrbWithIndex(new Index2D(x, y));
                    if (!matched.Contains(it))
                    {
                        continue;
                    }

                    for (int h = y + 1; h < Board.Rows; h++)
                    {
                        PuzzleOrb it2 = GetOrbWithIndex(new Index2D(x, h));
                        if (!matched.Contains(it2))
                        {
                            SwapOrbPlaces(it, it2);
                            int index = matched.IndexOf(it);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void TraverseRight(PuzzleOrb orb, List <List <PuzzleOrb> > matchGroup, List <PuzzleOrb> match)
        {
            PuzzleOrb orbRight = GetOrbWithIndex(orb.index.RightIndex);

            if (orbRight != null && !HasOrbAlreadyBeenTraversed(orbRight) && orb.HasMatchingColor(orbRight))
            {
                match.Add(orbRight);
                TraverseRight(orbRight, matchGroup, match);
                Traversed.Add(orbRight);

                List <PuzzleOrb> vertical = new List <PuzzleOrb>()
                {
                    orbRight
                };
                TraverseUp(orbRight, matchGroup, vertical);
                TraverseDown(orbRight, matchGroup, vertical);
            }
            else
            {
                if (match.Count > 2 && !matchGroup.Contains(match))
                {
                    matchGroup.Add(match);
                }
            }
        }
Exemple #3
0
        private void TraverseOrb(PuzzleOrb traverseOrb, List <List <PuzzleOrb> > matchGroup)
        {
            List <PuzzleOrb> horizontal = new List <PuzzleOrb>()
            {
                traverseOrb
            };

            TraverseRight(traverseOrb, matchGroup, horizontal);
            TraverseLeft(traverseOrb, matchGroup, horizontal);

            List <PuzzleOrb> vertical = new List <PuzzleOrb>()
            {
                traverseOrb
            };

            TraverseUp(traverseOrb, matchGroup, vertical);
            TraverseDown(traverseOrb, matchGroup, vertical);

            //First orb should not be added to traversed list before traversal has been completed due to how it would cause problems with circular traversal.
            //I.E two columns of 3 red orbs would only clear the second column because 7th traversal cannot be completed due to 1th being already in tarversed list.
            //[5][4]
            //[6][3]
            //[1][2]

            if (!Traversed.Contains(traverseOrb))
            {
                Traversed.Add(traverseOrb);
            }
        }
Exemple #4
0
 public void FillBoardWithNewOrbs()
 {
     for (int y = 0; y < Board.Rows; y++)
     {
         for (int x = 0; x < Board.Columns; x++)
         {
             PuzzleOrb newOrb = new PuzzleOrb(x, y, OrbColorHelper.GetRandomOrbColor());
             Board[y, x] = newOrb;
         }
     }
 }
Exemple #5
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;
        }
Exemple #6
0
        public void CheckForMatches()
        {
            Traversed.Clear();
            AllMatches.Clear();

            for (int y = 0; y < Board.Rows; y++)
            {
                for (int x = 0; x < Board.Columns; x++)
                {
                    PuzzleOrb orb = GetOrbWithIndex(new Index2D(x, y));
                    if (Traversed.Contains(orb))
                    {
                        continue;
                    }

                    List <List <PuzzleOrb> > matchGroup = new List <List <PuzzleOrb> >();
                    TraverseOrb(orb, matchGroup);

                    if (matchGroup.Count > 0)
                    {
                        List <PuzzleOrb> matchedOrbs = new List <PuzzleOrb>();
                        for (int i = 0; i < matchGroup.Count; i++)
                        {
                            for (int j = 0; j < matchGroup[i].Count; j++)
                            {
                                if (!matchedOrbs.Contains(matchGroup[i][j]))
                                {
                                    matchedOrbs.Add(matchGroup[i][j]);
                                }
                            }
                        }
                        AllMatches.Add(matchedOrbs);
                    }
                }
            }
        }
Exemple #7
0
 private bool HasOrbAlreadyBeenTraversed(PuzzleOrb orb)
 {
     return(Traversed.Contains(orb));
 }
Exemple #8
0
 public void SwapOrbPlaces(PuzzleOrb firstOrb, PuzzleOrb secondOrb)
 {
     SwapOrbPlaces(firstOrb.index, secondOrb.index);
 }