//Вывод информации времени об игре private void ShowTimeInterval(MineSweeperModel model) { Console.WriteLine("Время игры: {0}", model.Time.ToString()); }
//Вывод игрового поля public int DrawGameBoard(MineSweeperModel model) { ShowTimeInterval(model); int interval = 2; Console.Write("".PadLeft(interval, ' ')); for (int i = 1; i <= model.cellBoard.Width; i++) { Console.Write("{0}", i.ToString().PadLeft(interval + 1, ' ')); } Console.Write(Environment.NewLine); Console.Write("".PadLeft(interval, ' ')); for (int i = 0; i < (interval + 1) * model.cellBoard.Width + 1; i++) { Console.Write("-"); } Console.Write(Environment.NewLine); for (int i = 1; i <= model.cellBoard.Height; i++) { Console.Write("{0}|", i.ToString().PadLeft(interval, ' ')); for (int j = 1; j <= model.cellBoard.Width; j++) { int x = j - 1; int y = i - 1; if (Y == y && X == x) { Console.BackgroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Black; } //стиль ячек при рзпечатывании if (model.cellBoard.Cells[x, y].IsOpened) { int res = (int)model.cellBoard.Cells[x, y].Type; Console.Write("["); if (res == (int)ModelGame.Type.Mine) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("*"); } else { Console.ForegroundColor = (ConsoleColor)res; Console.Write(res.ToString()); } Console.ResetColor(); Console.Write("]"); } else if (model.cellBoard.Cells[x, y].IsFlagged) { Console.Write("["); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("{0}", "@"); Console.Write("]"); Console.ResetColor(); } else { Console.Write("[{0}]", "-"); Console.ResetColor(); } } Console.Write(Environment.NewLine); } Console.WriteLine(Environment.NewLine); foreach (var value in Enum.GetValues(typeof(GameManagment))) { Console.WriteLine(GetDescription((GameManagment)value)); } ConsoleKeyInfo ckey = Console.ReadKey(); //Упарвление движением по полю вниз if (ckey.Key == ConsoleKey.DownArrow) { if (Y == width - 1) { Y = 0; } else { Y++; } } //Упарвление движением по полю вверх else if (ckey.Key == ConsoleKey.UpArrow) { if (Y <= 0) { Y = width - 1; } else { Y--; } } //Упарвление движением по полю вправо if (ckey.Key == ConsoleKey.RightArrow) { if (X == height - 1) { X = 0; } else { X++; } } //Упарвление движением по полю влево else if (ckey.Key == ConsoleKey.LeftArrow) { if (X <= 0) { X = height - 1; } else { X--; } } //Выйти в меню else if (ckey.Key == ConsoleKey.Escape) { Console.Clear(); return((int)GameManagment.Back); } //Флаг else if (ckey.Key == ConsoleKey.Z) { Console.Clear(); return((int)GameManagment.Flag); } //Открыть else if (ckey.Key == ConsoleKey.X) { Console.Clear(); return((int)GameManagment.Open); } Console.Clear(); return(-1); }
//Обновление 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("Вы победили!!!"); } }