public List <List <Item> > GetMatches(FindSeparating separating = FindSeparating.NONE, int matches = 3) { var newCombines = new List <List <Item> >(); countedSquares = new Hashtable(); countedSquares.Clear(); for (var col = 0; col < fieldData.maxCols; col++) { for (var row = 0; row < fieldData.maxRows; row++) { if (GetSquare(col, row) != null) { if (!countedSquares.ContainsValue(GetSquare(col, row).Item)) { var newCombine = GetSquare(col, row).FindMatchesAround(separating, matches, countedSquares); if (newCombine.Count >= matches) { newCombines.Add(newCombine); } } } } } return(newCombines); }
Hashtable FindMoreMatches(int spr_COLOR, Hashtable countedSquares, FindSeparating separating, Hashtable countedSquaresGlobal = null) { bool globalCounter = true; if (countedSquaresGlobal == null) { globalCounter = false; countedSquaresGlobal = new Hashtable(); } ccc++; if (this.item == null) { return(countedSquares); } if (this.item.destroying) { return(countedSquares); } // if (LevelManager.THIS.countedSquares.ContainsValue(this.item) && globalCounter) return countedSquares; if (this.item.color == spr_COLOR && !countedSquares.ContainsValue(this.item) && this.item.currentType != ItemsTypes.INGREDIENT) { if (LevelManager.THIS.onlyFalling && this.item.justCreatedItem) { countedSquares.Add(countedSquares.Count - 1, this.item); } else if (!LevelManager.THIS.onlyFalling) { countedSquares.Add(countedSquares.Count - 1, this.item); } else { return(countedSquares); } if (separating == FindSeparating.VERTICAL) { if (GetNeighborTop() != null) { countedSquares = GetNeighborTop().FindMoreMatches(spr_COLOR, countedSquares, FindSeparating.VERTICAL); } if (GetNeighborBottom() != null) { countedSquares = GetNeighborBottom().FindMoreMatches(spr_COLOR, countedSquares, FindSeparating.VERTICAL); } } else if (separating == FindSeparating.HORIZONTAL) { if (GetNeighborLeft() != null) { countedSquares = GetNeighborLeft().FindMoreMatches(spr_COLOR, countedSquares, FindSeparating.HORIZONTAL); } if (GetNeighborRight() != null) { countedSquares = GetNeighborRight().FindMoreMatches(spr_COLOR, countedSquares, FindSeparating.HORIZONTAL); } } } return(countedSquares); }
public List <Item> FindMatchesAround(FindSeparating separating = FindSeparating.NONE, int matches = 3, Hashtable countedSquaresGlobal = null) { bool globalCounter = true; List <Item> newList = new List <Item>(); if (countedSquaresGlobal == null) { globalCounter = false; countedSquaresGlobal = new Hashtable(); } Hashtable countedSquares = new Hashtable(); countedSquares.Clear(); if (this.item == null) { return(newList); } if (separating != FindSeparating.HORIZONTAL) { countedSquares = this.FindMoreMatches(this.item.color, countedSquares, FindSeparating.VERTICAL, countedSquaresGlobal); } foreach (DictionaryEntry de in countedSquares) { LevelManager.THIS.countedSquares.Add(LevelManager.THIS.countedSquares.Count - 1, de.Value); } if (countedSquares.Count < matches) { countedSquares.Clear(); } if (separating != FindSeparating.VERTICAL) { countedSquares = this.FindMoreMatches(this.item.color, countedSquares, FindSeparating.HORIZONTAL, countedSquaresGlobal); } foreach (DictionaryEntry de in countedSquares) { LevelManager.THIS.countedSquares.Add(LevelManager.THIS.countedSquares.Count - 1, de.Value); } if (countedSquares.Count < matches) { countedSquares.Clear(); } foreach (DictionaryEntry de in countedSquares) { newList.Add((Item)de.Value); } // print(countedSquares.Count); return(newList); }
public List <Item> FindMatchesAround(FindSeparating separating = FindSeparating.NONE, int matches = 3, Hashtable countedSquaresGlobal = null) { var globalCounter = true; var newList = new List <Item>(); if (countedSquaresGlobal == null) { globalCounter = false; countedSquaresGlobal = new Hashtable(); } var countedSquares = new Hashtable(); countedSquares.Clear(); if (Item == null) { return(newList); } if (!Item.Combinable) { return(newList); } // if (separating != FindSeparating.HORIZONTAL) // { countedSquares = FindMoreMatches(Item.color, countedSquares, FindSeparating.VERTICAL, countedSquaresGlobal); // } foreach (DictionaryEntry de in countedSquares) { field.countedSquares.Add(field.countedSquares.Count - 1, de.Value); } foreach (DictionaryEntry de in countedSquares) { field.countedSquares.Add(field.countedSquares.Count - 1, de.Value); } if (countedSquares.Count < matches) { countedSquares.Clear(); } foreach (DictionaryEntry de in countedSquares) { newList.Add((Item)de.Value); } // print(countedSquares.Count); return(newList.Distinct().ToList()); }