Example #1
0
 public override List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData, List <Match> previousMatches)
 {
     foreach (var acc in accumulators)
     {
         previousMatches = acc.FindMatches(grid, swapData, previousMatches);
     }
     return(previousMatches);
 }
Example #2
0
 private MatchElement MatchElementAt(RuntimeGridData grid, int i, int j)
 {
     return(new MatchElement
     {
         i = i,
         j = j,
         tile = grid.GetTileAt(i, j).gameObject
     });
 }
Example #3
0
        public override List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData, List <Match> previousMatches)
        {
            for (int i = 0; i < previousMatches.Count; i++)
            {
                var match = previousMatches[i];
                match.causeElem = System.Array.FindIndex(match.elements, item =>
                {
                    var pos = new Vector2Int(item.i, item.j);
                    return(pos == swapData.swappedPos1 || pos == swapData.swappedPos2);
                });

                previousMatches[i] = match;
            }
            return(previousMatches);
        }
Example #4
0
        public override List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData, List <Match> previousMatches)
        {
            var potentialMatch = new List <MatchElement>();
            var lastTileTag    = "";

            // check for vertical matches
            for (int x = 0; x < grid.Width; x++)
            {
                for (int y = 0; y < grid.Height; y++)
                {
                    lastTileTag = ProcessTile(previousMatches, potentialMatch, grid, lastTileTag, x, y);
                }

                if (potentialMatch.Count > 2)
                {
                    previousMatches.Add(new Match(potentialMatch.ToArray()));
                }
                potentialMatch.Clear();
                lastTileTag = "";
            }


            // check for horizontal matches
            for (int y = 0; y < grid.Height; y++)
            {
                for (int x = 0; x < grid.Width; x++)
                {
                    lastTileTag = ProcessTile(previousMatches, potentialMatch, grid, lastTileTag, x, y);
                }

                if (potentialMatch.Count > 2)
                {
                    previousMatches.Add(new Match(potentialMatch.ToArray()));
                }
                potentialMatch.Clear();
                lastTileTag = "";
            }

            return(previousMatches);
        }
Example #5
0
        public override List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData, List <Match> previousMatches)
        {
            List <Match> merged = new List <Match>();

            bool mergeFound = false;

            for (int i = 0; i < previousMatches.Count; i++)
            {
                Match m = previousMatches[i];
                for (int j = i + 1; j < previousMatches.Count; j++)
                {
                    if (m.OverlapsWith(previousMatches[j]))
                    {
                        // create the merged Match

                        var l = new List <MatchElement>(m.elements.Length + previousMatches[j].elements.Length);
                        l.AddRange(m.elements);
                        l.AddRange(previousMatches[j].elements);
                        var mergedElements = l.Distinct(new MatchComparator()).ToArray();

                        // add it to the merged list
                        merged.Add(new Match(mergedElements));
                        // make sure we dont add this match to the merged list twice
                        previousMatches.RemoveAt(j);
                        // make sure we dont add the 3 at the end of this
                        mergeFound = true;
                    }
                }

                if (!mergeFound)
                {
                    merged.Add(m);
                }
            }


            return(merged);
        }
Example #6
0
        private string ProcessTile(List <Match> matches, List <MatchElement> potentialMatch, RuntimeGridData grid, string lastTileTag, int x, int y)
        {
            var tile = grid.GetTileAt(x, y);

            if (tile == null)
            {
                return("");
            }



            // if first element
            if (potentialMatch.Count == 0)
            {
                potentialMatch.Add(MatchElementAt(grid, x, y));
            }
            // if same as the previously seen tiles
            else if (tile.CompareTag(lastTileTag))
            {
                potentialMatch.Add(MatchElementAt(grid, x, y));
            }
            // if this tag does not match that of the previous tile but we have built up enough for a match then add that new match
            else if (potentialMatch.Count > 2)
            {
                matches.Add(new Match(potentialMatch.ToArray()));
                potentialMatch.Clear();

                potentialMatch.Add(MatchElementAt(grid, x, y));
            }
            // not the same tag as before so ditch list we were building and start again
            else
            {
                potentialMatch.Clear();

                potentialMatch.Add(MatchElementAt(grid, x, y));
            }

            return(tile.tag);
        }
Example #7
0
 public abstract List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData, List <Match> previousMatches);
Example #8
0
 public List <Match> FindMatches(RuntimeGridData grid, SwapEventData swapData)
 {
     return(FindMatches(grid, swapData, new List <Match>()));
 }