private bool CheckMatches(int x, int y, MatchesType type) { var addX = (type == MatchesType.DIAGONAL_LEFT ? -1 : type == MatchesType.VERTICAL ? 0 : 1); var addY = (type == MatchesType.HORIZONTAL ? 0 : 1); var pX = x + addX; var pY = y + addY; var hasMatches = false; List <MatchPiece> pieceList = new List <MatchPiece>() { board[x][y] }; var currentType = board[x][y].type; while (InBounds(pX, pY) && currentType.CompareTo(board[pX][pY].type) == 0 && !board[pX][pY].HasMatch(type)) { pieceList.Add(board[pX][pY]); pX = pX + addX; pY = pY + addY; } if (pieceList.Count > 2) { pieceList.ForEach(p => p.SetMatch(type)); ExplodePieces(pieceList); hasMatches = true; } return(hasMatches); }
public bool HasMatch(MatchesType type) { switch (type) { case MatchesType.DIAGONAL_LEFT: return(diagonalMatchLeft); case MatchesType.DIAGONAL_RIGHT: return(diagonalMatchRight); case MatchesType.HORIZONTAL: return(horizontalMatch); case MatchesType.VERTICAL: return(verticalMatch); } return(false); }
public void SetMatch(MatchesType type, bool value = true) { switch (type) { case MatchesType.DIAGONAL_LEFT: diagonalMatchLeft = value; break; case MatchesType.DIAGONAL_RIGHT: diagonalMatchRight = value; break; case MatchesType.HORIZONTAL: horizontalMatch = value; break; case MatchesType.VERTICAL: verticalMatch = value; break; } }