public int DemineNearMines(CellClassic cell) { int nearMinesCount = 0; int nearFlagsCount = 0; for (int i = cell.Row - 1; i < cell.Row + 2; i++) { for (int j = cell.Column - 1; j < cell.Column + 2; j++) { try { if (_field[i, j].IsMine) nearMinesCount++; if (_field[i, j].IsFlag) nearFlagsCount++; if (nearFlagsCount == nearMinesCount) { if (_field[i, j].IsMine) _field[i, j].IsDemine=true; else if (_field[i, j].IsClose) _field[i, j].IsClose = false; } else { return -1; } } catch { } } } return nearMinesCount; }
void CellShortTapHandler(CellClassic cell) { if (cell.IsFlag) return; else if (cell.IsClose) field.OpenCell(cell); }
void CellLongTapHandler(CellClassic cell) { #if UNITY_ANDROID || UNITY_IPHONE Handheld.Vibrate(); #endif if (cell.IsClose) cell.IsFlag = !cell.IsFlag; else { int deminedMinesNearCell = field.DemineNearMines(cell); } }
public FieldClassic(int rowCount,int colCount) { MinesCount = 0; OpenedCells = 0; if(_field==null) _field=new CellClassic[rowCount,colCount]; else { return; } for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { _field[i,j]=new CellClassic(i,j); CreateCellGameObject(_field[i,j]); } } }
void CellLongTapHandler(CellClassic cell) { #if UNITY_ANDROID || UNITY_IPHONE Handheld.Vibrate(); #endif if (cell.IsClose) cell.IsFlag = !cell.IsFlag; else { if (field.DemineNearMines(cell) < 0) { GameOver(false); } else if(field.CheckForWin()) { GameOver(true); } } }
public FieldClassic(int rowCount,int colCount) { GameObject.Find("Field").GetComponent<UITable>().columns = colCount; MinesCount = 0; OpenedCells = 0; DeminedCells = 0; if(_field==null) _field=new CellClassic[rowCount,colCount]; else { return; } for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { _field[i,j]=new CellClassic(i,j); CreateCellGameObject(_field[i,j]); } } }
public int DemineNearMines(CellClassic cell) { int nearMinesCount = 0; int nearFlagsCount = 0; if (cell.NearMinesCount == 0) { Debug.Log("There are no mines around"); return 0; } for (int i = cell.Row - 1; i < cell.Row + 2; i++) { for (int j = cell.Column - 1; j < cell.Column + 2; j++) { try { if (_field[i, j].IsMine&&!_field[i,j].IsDemine) nearMinesCount++; if (_field[i, j].IsFlag/*||_field[i,j].IsDemine*/) nearFlagsCount++; } catch { } } } if (nearFlagsCount != nearMinesCount) { Debug.Log("Flags not much mines count" + nearFlagsCount.ToString() + " " + nearMinesCount.ToString()); return 0; } for (int i = cell.Row - 1; i < cell.Row + 2; i++) { for (int j = cell.Column - 1; j < cell.Column + 2; j++) { try { if(!_field[i,j].IsClose || _field[i,j].IsDemine) continue; if (!_field[i, j].IsMine) { _field[i, j].IsClose = false; if (_field[i, j].NearMinesCount == 0) { SearchForFreeNearCells(_field[i, j]); } OpenedCells++; } else { if (!_field[i, j].IsFlag) { return -1; } else { _field[i, j].IsDemine = true; _field[i, j].IsFlag = false; } } } catch { } } } DeminedCells += nearMinesCount; return nearMinesCount; }
void CreateCellGameObject(CellClassic cell) { //var cellGO= GameObject.Instantiate(Resources.Load("prefabs/game/classic/cell")) as GameObject; var cellGO = NGUITools.AddChild(GameObject.Find("Field").gameObject,Resources.Load("prefabs/game/classic/cell") as GameObject); cellGO.GetComponent<CellViewClassic>().Model = cell; cellGO.name = cell.Row.ToString() + "_" + cell.Column.ToString() + "_" + "cell"; cellGO.transform.parent = GameObject.Find("Field").transform; GameObject.Find("Field").GetComponent<UITable>().Reposition(); // var cellSprite = cellGO.GetComponent<CellViewClassic>().close; //cellGO.transform.localPosition = new Vector3(cell.Row * cellSprite.renderer.bounds.size.x, cell.Column * cellSprite.renderer.bounds.size.y, 0); }
public int SearchForFreeNearCells(CellClassic cell) { //int delay=1; for (int i = cell.Row - 1; i < cell.Row + 2; i++) { for (int j = cell.Column - 1; j < cell.Column + 2; j++) { try { if (_field[i, j].IsClose == true) { _field[i, j].IsClose = false; _field[i, j].IsFlag = false; OpenedCells++; if (_field[i, j].NearMinesCount == 0) { SearchForFreeNearCells(_field[i, j]); } } } catch { } } } return OpenedCells; }
public int OpenCell(CellClassic cell) { cell.IsClose = false; OpenedCells++; if (cell.IsMine) { return -1; } else if (cell.NearMinesCount == 0) { cell.IsClose = false; return 1+SearchForFreeNearCells(cell); } else { cell.IsClose = false; return 1; } }
/* void OnTap(TapGestureRecognizer gesture) { Debug.Log("Tap"); }*/ void CellShortTapHandler(CellClassic cell) { if (cell.IsFlag) return; else if (cell.IsClose) { var result = field.OpenCell(cell); if(result<0) GameOver(false); else if(field.CheckForWin()) GameOver(true); } }
public void OpenCell(CellClassic cell) { cell.IsClose = false; OpenedCells++; if (cell.IsMine) { SapperClassic.Instance.GameOver(); } else if (cell.NearMinesCount == 0) { cell.IsClose = false; SearchForFreeNearCells(cell); } else { cell.IsClose = false; } Debug.Log(OpenedCells.ToString()+"________"+MinesCount.ToString()); if (_field.GetLength(0)*_field.GetLength(1) - OpenedCells == MinesCount) { Debug.Log("YYYYYWWWWWWWWWWWWWWWWW"); Application.Quit(); } }