private void CheckCells(LlkCell lc1, LlkCell lc2) { if (lc1.iType != lc2.iType) { lc1.bSelected = false; lc2.bSelected = false; lSelectedCells.Clear(); return; } if (CheckOneLine(lc1, lc2) || CheckTwoLines(lc1, lc2) || CheckThreeLines(lc1, lc2)) { lc1.bCleared = true; lc2.bCleared = true; clearedCellNum += 2; lastSecond += 1; } else { lc1.bSelected = false; lc2.bSelected = false; } lSelectedCells.Clear(); }
private void Reinit() { bGameOver = false; bLevelUp = false; lastSecond = fullSeconds; maxRow = iDiff * 2 + 4; maxCol = iDiff * 2 + 2; clearedCellNum = 0; cellNum = 0; llkCells.Clear(); lSelectedCells.Clear(); for (int i = 0; i < maxRow; i++) { LlkList ll = new LlkList(); for (int j = 0; j < maxCol; j++) { LlkCell lc = new LlkCell(); ll.Add(lc); lc.x = size * j + posOffset; lc.y = size * i + posOffset; lc.row = i; lc.col = j; lc.bCleared = true; } llkCells.Add(ll); } for (int i = 0; i < (maxRow - 2) * (maxCol - 2) / 2; i++) { int rt = Random.Range(0, iDiff * 2); int rr; int rc; do { rr = Random.Range(0, maxRow - 2) + 1; rc = Random.Range(0, maxCol - 2) + 1; }while (llkCells[rr][rc].iType != -1); llkCells[rr][rc].SetType(rt); do { rr = Random.Range(0, maxRow - 2) + 1; rc = Random.Range(0, maxCol - 2) + 1; }while (llkCells[rr][rc].iType != -1); llkCells[rr][rc].SetType(rt); cellNum += 2; } }
private bool CheckTwoLines(LlkCell lc1, LlkCell lc2) { if (llkCells[lc1.row][lc2.col].bCleared && CheckOneLine(lc1, llkCells[lc1.row][lc2.col]) && CheckOneLine(llkCells[lc1.row][lc2.col], lc2)) { return(true); } if (llkCells[lc2.row][lc1.col].bCleared && CheckOneLine(lc1, llkCells[lc2.row][lc1.col]) && CheckOneLine(llkCells[lc2.row][lc1.col], lc2)) { return(true); } return(false); }
private void SetSelect(LlkCell lc) { if (lSelectedCells.Count == 0) { lc.bSelected = true; lSelectedCells.Add(lc); } else if (lSelectedCells.Count == 1) { if (lc == lSelectedCells[0]) { lc.bSelected = false; lSelectedCells.Clear(); return; } CheckCells(lc, lSelectedCells[0]); } }
private bool CheckOneLine(LlkCell lc1, LlkCell lc2) { int i; int ilarger; int ismaller; LlkCell tc; if (lc1.col == lc2.col) { ilarger = lc1.row > lc2.row ? lc1.row : lc2.row; ismaller = lc1.row < lc2.row ? lc1.row : lc2.row; for (i = ismaller + 1; i < ilarger; i++) { tc = llkCells[i][lc1.col]; if (!tc.bCleared) { return(false); } } return(true); } else if (lc1.row == lc2.row) { ilarger = lc1.col > lc2.col ? lc1.col : lc2.col; ismaller = lc1.col < lc2.col ? lc1.col : lc2.col; for (i = ismaller + 1; i < ilarger; i++) { tc = llkCells[lc1.row][i]; if (!tc.bCleared) { return(false); } } return(true); } return(false); }
private bool CheckThreeLines(LlkCell lc1, LlkCell lc2) { int i; LlkCell c; for (i = lc1.row - 1; i >= 0; i--) { c = llkCells[i][lc1.col]; if (c.bCleared) { if (CheckTwoLines(c, lc2)) { return(true); } } else { break; } } for (i = lc1.row + 1; i < maxRow; i++) { c = llkCells[i][lc1.col]; if (c.bCleared) { if (CheckTwoLines(c, lc2)) { return(true); } } else { break; } } for (i = lc1.col - 1; i >= 0; i--) { c = llkCells[lc1.row][i]; if (c.bCleared) { if (CheckTwoLines(c, lc2)) { return(true); } } else { break; } } for (i = lc1.col + 1; i < maxCol; i++) { c = llkCells[lc1.row][i]; if (c.bCleared) { if (CheckTwoLines(c, lc2)) { return(true); } } else { break; } } return(false); }