private void _hasnull(int i, int j) { int row, column; if (mine.GameLevel == MineGameLevel.Beginner) { row = 9; column = 9; } else if (mine.GameLevel == MineGameLevel.Intermediate) { row = 16; column = 16; } else { row = 25; column = 25; } if (i < 0 || i > row - 1) { return; } if (j < 0 || j > column - 1) { return; } int _indexofCurrentPlace = (i * row) + (j + 1); MineBox index = ((MineBox)GamePanel.Controls[((i * row) + (j + 1)) - 1]); //if ((index.State == MineState.Close || index.State == MineState.Question) && (index.MineArround == 1 || index.MineArround == 2 || index.MineArround == 3 || index.MineArround == 4 || // index.MineArround == 5 || index.MineArround == 6 || index.MineArround == 7 || index.MineArround == 8)) if ((index.State == MineState.Close || index.State == MineState.Question) && (index.MineArround != 0)) { ((MineBox)GamePanel.Controls[_indexofCurrentPlace - 1]).State = MineState.Open; //SoundPlayer snd = new SoundPlayer(Path.Combine(Application.StartupPath, "click.wav")); //snd.Play(); return; } else if ((index.State == MineState.Close || index.State == MineState.Question) && !index.HasMine) { ((MineBox)GamePanel.Controls[_indexofCurrentPlace - 1]).State = MineState.Open; ClickaNullBox(i, j); } else { return; } //((MineBox)GamePanel.Controls[_indexofCurrentPlace - 1]).State = MineState.Open; //int index = ((i * 9) + (j + 1)); //if(((MineBox)GamePanel.Controls[index - 1]).State == MineState.Close ); //return ((MineBox)GamePanel.Controls[index - 1]).HasMine; //return mi[i, j].HasMine; }
private void StartGame(int row, int column, int mines, MineGameLevel gameLevel) { time1 = 0; time = false; _numberofGames += 1; timetoolStripStatusLabel3.Text = "0"; GamePanel.Controls.Clear(); mineNumbers = GuessMineNumbers(row, column, mines); for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { mine = new MineBox() { //Width = 20, //Height = 20, Left = j * 20, Top = i * 20, Index = (i * row) + (j + 1), State = MineState.Close, GameLevel = (MineGameLevel)gameLevel }; mine.OnGameOver += GameOver; mine.onClickNull += ClickaNullBox; mine.onSuccessEndGame += SuccessGameEnd; mine.OnClickFlagorQuestion += NumberofFlags; mine.HasMine = (mineNumbers.IndexOf(mine.Index) >= 0); GamePanel.Controls.Add(mine); //mi[i, j] = mine; } } for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { int neighbors = 0; if (_hasMine(row, column, i - 1, j - 1)) { neighbors++; } if (_hasMine(row, column, i, j - 1)) { neighbors++; } if (_hasMine(row, column, i + 1, j - 1)) { neighbors++; } if (_hasMine(row, column, i - 1, j)) { neighbors++; } if (_hasMine(row, column, i + 1, j)) { neighbors++; } if (_hasMine(row, column, i - 1, j + 1)) { neighbors++; } if (_hasMine(row, column, i, j + 1)) { neighbors++; } if (_hasMine(row, column, i + 1, j + 1)) { neighbors++; } int index = ((i * row) + (j + 1)); ((MineBox)GamePanel.Controls[index - 1]).MineArround = neighbors; //mi[i, j].MineArround = neighbors; } } }