示例#1
0
        public string GetConsoleElement()
        {
            Dictionary <TileStateEnum, string> elements = new Dictionary <TileStateEnum, string>();

            elements.Add(TileStateEnum.HIDDEN, "*");
            elements.Add(TileStateEnum.FLAGGED, "|");
            elements.Add(TileStateEnum.REVEALED, MineCount.ToString());
            if (MineCount == 0 && TileState == TileStateEnum.REVEALED)
            {
                return(" ");
            }

            return(elements[TileState]);
        }
示例#2
0
        //Обновление 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("Вы победили!!!");
            }
        }