private static void ProcessGame() { bool isExit = true; while (isExit) { int seletedGameManagment = view.DrawGameBoard(model); switch (seletedGameManagment) { //возврат назад case (int)GameManagment.Back: model.StopTimer(); isExit = false; break; //открыти ячейки case (int)GameManagment.Open: model.OpenCell(view.X, view.Y); break; //отмтить/убрать флаг case (int)GameManagment.Flag: model.SetFlagCoordinate(view.X, view.Y); break; } //проверка статуса игры посл хода if (model.GetStatusGame() == GameStatus.GameOver) { view.DrawGameOver(); seletedGameManagment = view.DrawGameBoard(model); isExit = false; } if (model.GetStatusGame() == GameStatus.Win) { view.DrawWin(); string name = view.SetNameHightScore(model.CheckResult()); model.SaveResultHightScore(name); seletedGameManagment = view.DrawGameBoard(model); isExit = false; } } }
//Обновление view после события public void UpdateView(MineSweeperModel model) { var iterator = model.cellBoard.GetEnumerator(); lbCountMine.Text = MineCount.ToString(); while (iterator.MoveNext()) { int x = iterator.Current.X; int y = iterator.Current.Y; if (iterator.Current.IsOpened) { int type = (int)iterator.Current.Type; //Выставление соответсвующей картинки для типа мина if (type == (int)ModelGame.Type.Mine) { SetImageCellMine(iterator.Current, x, y); continue; } //Выставление соответсвующей картинки для не мин SetImageCellNotMine(type, x, y); continue; } else if (iterator.Current.IsFlagged) { cells[x, y].Image = Properties.Resources.flag; } else { cells[x, y].Image = Properties.Resources.unmarked; } } //проверка игря на проигрыш if (model.GetStatusGame() == GameStatus.GameOver) { GameTimer.Stop(); //Отменить действие нажатия на оставшихся ячейках iterator = model.cellBoard.GetEnumerator(); while (iterator.MoveNext()) { int x = iterator.Current.X; int y = iterator.Current.Y; if (iterator.Current.IsFlagged && (iterator.Current.Type != ModelGame.Type.Mine)) { cells[x, y].Image = Properties.Resources.notmine; } if (!iterator.Current.IsOpened) { cells[x, y].MouseDown -= new MouseEventHandler(bttnClick); } } btnFace.Image = Properties.Resources.smiley_lose; } //проверка игры на выигрыш if (model.GetStatusGame() == GameStatus.Win) { GameTimer.Stop(); MessageBox.Show("Вы победили!!!"); } }