/// <summary> /// /// </summary> /// <param name="row">从0索引开始</param> /// <param name="col">从0索引开始</param> /// <param name="direction"></param> /// <param name="customColor"></param> /// <param name="outList"></param> /// <returns></returns> private bool MatchThree(int row, int col, CandyDirection direction, CandyColor customColor, List<CellData> outList = null) { bool bMatch = false; switch (direction) { case CandyDirection.Left: if (col > 1) { bMatch = (m_cellDatas[row, col - 2].Color == m_cellDatas[row, col - 1].Color && m_cellDatas[row, col - 1].Color == customColor); if (bMatch && outList != null) { outList.Add(m_cellDatas[row, col]); outList.Add(m_cellDatas[row, col - 1]); outList.Add(m_cellDatas[row, col - 2]); } } break; case CandyDirection.Right: if (col < Cols - 2) { bMatch = (customColor == m_cellDatas[row, col + 1].Color && m_cellDatas[row, col + 1].Color == m_cellDatas[row, col + 2].Color); if (bMatch && outList != null) { outList.Add(m_cellDatas[row, col]); outList.Add(m_cellDatas[row, col + 1]); outList.Add(m_cellDatas[row, col + 2]); } } break; case CandyDirection.Upper: if (row > 1) { bMatch = (m_cellDatas[row - 2, col].Color == m_cellDatas[row - 1, col].Color && m_cellDatas[row - 1, col].Color == customColor); if (bMatch && outList != null) { outList.Add(m_cellDatas[row, col]); outList.Add(m_cellDatas[row - 1, col]); outList.Add(m_cellDatas[row - 2, col]); } } break; case CandyDirection.Down: if (row < Rows - 2) { bMatch = (customColor == m_cellDatas[row + 1, col].Color && m_cellDatas[row + 1, col].Color == m_cellDatas[row + 2, col].Color); if (bMatch && outList != null) { outList.Add(m_cellDatas[row, col]); outList.Add(m_cellDatas[row + 1, col]); outList.Add(m_cellDatas[row + 2, col]); } } break; } return bMatch; }
private bool MatchThree(int row, int col, CandyDirection direction) { return MatchThree(row, col, direction, m_cellDatas[row, col].Color); }
/// <summary> /// 是否操作一步就可以匹配 /// </summary> /// <param name="row"></param> /// <param name="col"></param> /// <param name="direction"></param> /// <param name="outList"></param> /// <returns></returns> private bool WillMatchThree(int row, int col, CandyDirection direction, List<CellData> outList = null) { bool bMatch = false; CandyColor checkColor = m_cellDatas[row, col].Color; switch (direction) { case CandyDirection.Left: if (col > 1) { bool bUpperMath = (row > 0 && m_cellDatas[row - 1, col - 2].Color == checkColor); bool bDownMath = (row < Rows - 1 && m_cellDatas[row + 1, col - 2].Color == checkColor); bMatch = checkColor == m_cellDatas[row, col - 1].Color && (bUpperMath || bDownMath); if (bMatch && outList != null) { outList.Add(bUpperMath ? m_cellDatas[row - 1, col - 2] : m_cellDatas[row + 1, col - 2]); outList.Add(m_cellDatas[row, col - 1]); outList.Add(m_cellDatas[row, col]); } } break; case CandyDirection.Right: if (col < Cols - 2) { bool bUpperMath = (row > 0 && m_cellDatas[row - 1, col + 2].Color == checkColor); bool bDownMath = (row < Rows - 1 && m_cellDatas[row + 1, col + 2].Color == checkColor); bMatch = checkColor == m_cellDatas[row, col + 1].Color && (bUpperMath || bDownMath); if (bMatch && outList != null) { outList.Add(bUpperMath ? m_cellDatas[row - 1, col + 2] : m_cellDatas[row + 1, col + 2]); outList.Add(m_cellDatas[row, col + 1]); outList.Add(m_cellDatas[row, col]); } } break; case CandyDirection.Upper: if (row > 1) { bool bLeftMatch = (col > 0 && m_cellDatas[row - 2, col - 1].Color == checkColor); bool bRightMatch = col < Cols - 1 && m_cellDatas[row - 2, col + 1].Color == checkColor; bMatch = (checkColor == m_cellDatas[row - 1, col].Color && (bLeftMatch || bRightMatch)); if (bMatch && outList != null) { outList.Add(bLeftMatch ? m_cellDatas[row - 2, col - 1] : m_cellDatas[row - 2, col + 1]); outList.Add(m_cellDatas[row - 1, col]); outList.Add(m_cellDatas[row, col]); } } break; case CandyDirection.Down: if (row < Rows - 2) { bool bLeftMatch = (col > 0 && m_cellDatas[row + 2, col - 1].Color == checkColor); bool bRightMatch = col < Cols - 1 && m_cellDatas[row + 2, col + 1].Color == checkColor; bMatch = (checkColor == m_cellDatas[row + 1, col].Color && (bLeftMatch || bRightMatch)); if (bMatch && outList != null) { outList.Add(bLeftMatch ? m_cellDatas[row + 2, col - 1] : m_cellDatas[+2, col + 1]); outList.Add(m_cellDatas[row + 1, col]); outList.Add(m_cellDatas[row, col]); } } break; } return bMatch; }