private void ConsolidateMatches(MatchData match1, MatchData match2) { while (match2.indexList.Count > 0) { var newIndex = match2.indexList[0]; if (match1.indexList.Contains(newIndex) == false) match1.AddIndex(match2.indexList[0]); match2.indexList.RemoveAt(0); } }
private void ConsolidateMatches(MatchData match1, MatchData match2) { while (match2.indexList.Count > 0) { var newIndex = match2.indexList[0]; if (match1.indexList.Contains(newIndex) == false) { match1.AddIndex(match2.indexList[0]); } match2.indexList.RemoveAt(0); } }
public bool CheckBoardForMatches() { BoardMatchData.Clear(); List<MatchData> horizontalMatches = new List<MatchData>(); List<MatchData> verticalMatches = new List<MatchData>(); // firstly go through the board and find the horizontal matches for (int y = 0; y < BoardConfig.Height; y++) { int xIndex = 0; while (xIndex < BoardConfig.Width) { var baseGem = PuzzleBoard.GetGemAtPos(xIndex, y); var xMatch = MatchRightCount(xIndex, y, baseGem) + 1; if (xMatch > 2) { MatchData match = new MatchData(baseGem); while (xMatch > 0) { match.AddIndex(BoardConfig.GetIndex(xIndex, y)); xMatch--; xIndex++; } horizontalMatches.Add(match); } else { xIndex += xMatch; } } } //now the vertical matches for (int x = 0; x < BoardConfig.Width; x++) { int yIndex = 0; while (yIndex < BoardConfig.Height) { var baseGem = PuzzleBoard.GetGemAtPos(x, yIndex); var yMatch = MatchDownCount(x, yIndex, baseGem) + 1; if (yMatch > 2) { MatchData match = new MatchData(baseGem); while (yMatch > 0) { match.AddIndex(BoardConfig.GetIndex(x, yIndex)); yMatch--; yIndex++; } verticalMatches.Add(match); } else { yIndex += yMatch; } } } if (horizontalMatches.Count == 0 && verticalMatches.Count == 0) return false; if (horizontalMatches.Count > 0 && verticalMatches.Count > 0) { //horizontalMatches.Sort // go through all the horizontal matches and see if there's any vertical matches that cross // and if so it grabs the largest one and tags it as to be used with the horizontal and move on. } BoardMatchData.matchesFound.AddRange(horizontalMatches); BoardMatchData.matchesFound.AddRange(verticalMatches); foreach (var match in BoardMatchData.matchesFound) { foreach (var index in match.indexList) { if (BoardMatchData.markedDestroy.Contains(index) == false) BoardMatchData.markedDestroy.Add(index); } } return BoardMatchData.matchesFound.Count > 0; }
private MatchData GetOneIndexMatchData(int x, int y) { var index = BoardConfig.GetIndex(x, y); int baseGem = PuzzleBoard.GetGemAtPos(x, y); if (baseGem == GemConverter.NoGem) return null; var leftMatch = MatchLeftCount(x, y, baseGem); var rightMatch = MatchRightCount(x, y, baseGem); var upMatch = MatchUpCount(x, y, baseGem); var downMatch = MatchDownCount(x, y, baseGem); var horizontalMatch = 1 + leftMatch + rightMatch; var verticalMatch = 1 + upMatch + downMatch; if (horizontalMatch > 2 && verticalMatch > 2) { //corner match var matchData = new MatchData(index); matchData.AddIndex(BoardConfig.GetIndex(x, y)); while (leftMatch > 0) { leftMatch--; matchData.AddIndex(BoardConfig.GetIndex(x - leftMatch, y)); } while (rightMatch > 0) { rightMatch--; matchData.AddIndex(BoardConfig.GetIndex(x + rightMatch, y)); } while (upMatch > 0) { upMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, y - upMatch)); } while (downMatch > 0) { downMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, y + downMatch)); } return matchData; } else if (horizontalMatch > 2) { var startx = x + rightMatch; // simple side match var matchData = new MatchData(index); while (horizontalMatch > 0) { horizontalMatch--; matchData.AddIndex(BoardConfig.GetIndex(startx - horizontalMatch, y)); } return matchData; } else if (verticalMatch > 2) { var starty = y + downMatch; // vertical var matchData = new MatchData(index); while (verticalMatch > 0) { verticalMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, starty - verticalMatch)); } return matchData; } return null; }
public bool CheckBoardForMatches() { BoardMatchContainer.Clear(); List <MatchData> horizontalMatches = new List <MatchData>(); List <MatchData> verticalMatches = new List <MatchData>(); // firstly go through the board and find the horizontal matches for (int y = 0; y < BoardConfig.Instance.Height; y++) { int xIndex = 0; while (xIndex < BoardConfig.Instance.Width) { var gemCell = PuzzlePresentation.Instance.GetGemCellAtPos(xIndex, y); var xMatch = MatchRightCount(xIndex, y, gemCell) + 1; if (xMatch > 2) { MatchData match = new MatchData(gemCell.Type); while (xMatch > 0) { match.AddIndex(BoardConfig.Instance.GetIndex(xIndex, y)); xMatch--; xIndex++; } horizontalMatches.Add(match); } else { xIndex += xMatch; } } } //now the vertical matches for (int x = 0; x < BoardConfig.Instance.Width; x++) { int yIndex = 0; while (yIndex < BoardConfig.Instance.Height) { var gemCell = PuzzlePresentation.Instance.GetGemCellAtPos(x, yIndex); var yMatch = MatchDownCount(x, yIndex, gemCell) + 1; if (yMatch > 2) { MatchData match = new MatchData(gemCell.Type); while (yMatch > 0) { match.AddIndex(BoardConfig.Instance.GetIndex(x, yIndex)); yMatch--; yIndex++; } verticalMatches.Add(match); } else { yIndex += yMatch; } } } if (horizontalMatches.Count == 0 && verticalMatches.Count == 0) { return(false); } if (horizontalMatches.Count > 0 && verticalMatches.Count > 0) { //horizontalMatches.Sort // go through all the horizontal matches and see if there's any vertical matches that cross // and if so it grabs the largest one and tags it as to be used with the horizontal and move on. } BoardMatchContainer.matchesFound.AddRange(horizontalMatches); BoardMatchContainer.matchesFound.AddRange(verticalMatches); foreach (var match in BoardMatchContainer.matchesFound) { foreach (var index in match.indexList) { if (BoardMatchContainer.markedDestroy.Contains(index) == false) { BoardMatchContainer.markedDestroy.Add(index); } } } return(BoardMatchContainer.matchesFound.Count > 0); }
private MatchData GetOneIndexMatchData(int x, int y) { var index = BoardConfig.Instance.GetIndex(x, y); var gemCell = PuzzlePresentation.Instance.GetGemCellAtPos(x, y); if (IsCellMatchable(gemCell) == false) { return(null); } var leftMatch = MatchLeftCount(x, y, gemCell); var rightMatch = MatchRightCount(x, y, gemCell); var upMatch = MatchUpCount(x, y, gemCell); var downMatch = MatchDownCount(x, y, gemCell); var horizontalMatch = 1 + leftMatch + rightMatch; var verticalMatch = 1 + upMatch + downMatch; if (horizontalMatch > 2 && verticalMatch > 2) { //corner match var matchData = new MatchData(index); matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y)); while (leftMatch > 0) { leftMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x - leftMatch, y)); } while (rightMatch > 0) { rightMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x + rightMatch, y)); } while (upMatch > 0) { upMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y - upMatch)); } while (downMatch > 0) { downMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y + downMatch)); } return(matchData); } else if (horizontalMatch > 2) { var startx = x + rightMatch; // simple side match var matchData = new MatchData(index); while (horizontalMatch > 0) { horizontalMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(startx - horizontalMatch, y)); } return(matchData); } else if (verticalMatch > 2) { var starty = y + downMatch; // vertical var matchData = new MatchData(index); while (verticalMatch > 0) { verticalMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, starty - verticalMatch)); } return(matchData); } return(null); }
private MatchData GetOneIndexMatchData(int x, int y) { var index = BoardConfig.GetIndex(x, y); int baseGem = PuzzleBoard.GetGemAtPos(x, y); if (baseGem == GemConverter.NoGem) { return(null); } var leftMatch = MatchLeftCount(x, y, baseGem); var rightMatch = MatchRightCount(x, y, baseGem); var upMatch = MatchUpCount(x, y, baseGem); var downMatch = MatchDownCount(x, y, baseGem); var horizontalMatch = 1 + leftMatch + rightMatch; var verticalMatch = 1 + upMatch + downMatch; if (horizontalMatch > 2 && verticalMatch > 2) { //corner match var matchData = new MatchData(index); matchData.AddIndex(BoardConfig.GetIndex(x, y)); while (leftMatch > 0) { leftMatch--; matchData.AddIndex(BoardConfig.GetIndex(x - leftMatch, y)); } while (rightMatch > 0) { rightMatch--; matchData.AddIndex(BoardConfig.GetIndex(x + rightMatch, y)); } while (upMatch > 0) { upMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, y - upMatch)); } while (downMatch > 0) { downMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, y + downMatch)); } return(matchData); } else if (horizontalMatch > 2) { var startx = x + rightMatch; // simple side match var matchData = new MatchData(index); while (horizontalMatch > 0) { horizontalMatch--; matchData.AddIndex(BoardConfig.GetIndex(startx - horizontalMatch, y)); } return(matchData); } else if (verticalMatch > 2) { var starty = y + downMatch; // vertical var matchData = new MatchData(index); while (verticalMatch > 0) { verticalMatch--; matchData.AddIndex(BoardConfig.GetIndex(x, starty - verticalMatch)); } return(matchData); } return(null); }
private MatchData GetOneIndexMatchData(int x, int y) { var index = BoardConfig.Instance.GetIndex(x, y); var gemCell = PuzzlePresentation.Instance.GetGemCellAtPos(x, y); if (IsCellMatchable(gemCell) == false) return null; var leftMatch = MatchLeftCount(x, y, gemCell); var rightMatch = MatchRightCount(x, y, gemCell); var upMatch = MatchUpCount(x, y, gemCell); var downMatch = MatchDownCount(x, y, gemCell); var horizontalMatch = 1 + leftMatch + rightMatch; var verticalMatch = 1 + upMatch + downMatch; if (horizontalMatch > 2 && verticalMatch > 2) { //corner match var matchData = new MatchData(index); matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y)); while (leftMatch > 0) { leftMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x - leftMatch, y)); } while (rightMatch > 0) { rightMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x + rightMatch, y)); } while (upMatch > 0) { upMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y - upMatch)); } while (downMatch > 0) { downMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, y + downMatch)); } return matchData; } else if (horizontalMatch > 2) { var startx = x + rightMatch; // simple side match var matchData = new MatchData(index); while (horizontalMatch > 0) { horizontalMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(startx - horizontalMatch, y)); } return matchData; } else if (verticalMatch > 2) { var starty = y + downMatch; // vertical var matchData = new MatchData(index); while (verticalMatch > 0) { verticalMatch--; matchData.AddIndex(BoardConfig.Instance.GetIndex(x, starty - verticalMatch)); } return matchData; } return null; }