コード例 #1
0
ファイル: MainVM.cs プロジェクト: bombic94/minesweeper
        /// <summary>
        /// When game is lost, show all unmarked mines and wrongly marked mines.
        /// Show the field that contains mine which was stepped on as red mine
        /// </summary>
        /// <param name="clicked">Field which was stepped on - red mine</param>
        private void GameLost(POLE clicked)
        {
            List <POLE> listPoli = DBHelper.GetListPoli(this.OblastID);
            List <MINA> listMin  = DBHelper.GetListMin(this.OblastID);

            foreach (POLE p in listPoli)
            {
                foreach (MINA m in listMin)
                {
                    if (m.souradnice_x == p.souradnice_x && m.souradnice_y == p.souradnice_y)
                    {
                        p.Flag = true;
                    }
                }

                if (p.souradnice_x == clicked.souradnice_x && p.souradnice_y == clicked.souradnice_y)
                {
                    p.SteppedMine = true;
                }
                else if (p.je_mina == true && p.Flag == false)
                {
                    p.NotRevealed = true;
                }
                else if (p.je_mina == false && p.Flag == true)
                {
                    p.Flag      = false;
                    p.WrongFlag = true;
                }
            }

            this.Pole = new ObservableCollection <POLE>(listPoli);
        }
コード例 #2
0
ファイル: MainVM.cs プロジェクト: bombic94/minesweeper
        /// <summary>
        /// Reaction to left click of button.
        /// Show field on selected button and check from database, if game still continues.
        /// If yes, refresh field.
        /// If lost, call GameLost method
        /// If won, call GameWon method
        /// </summary>
        /// <param name="param">Button representing one field in game</param>
        private void ShowField(object param)
        {
            int gameState = (int)DBHelper.GetGame(this.OblastID).stav; // check if you can play

            if (gameState == (int)DBHelper.State.Playing)
            {
                Button b = param as Button;
                POLE   p = b.DataContext as POLE;

                DBHelper.ShowField(this.OblastID, p.souradnice_x, p.souradnice_y);

                gameState = (int)DBHelper.GetGame(this.OblastID).stav; // check state after move
                if (gameState != (int)DBHelper.State.Playing)
                {
                    this.Timer.Enabled = false; // stop counting time

                    if (gameState == (int)DBHelper.State.Won)
                    {
                        this.GameWon();
                        GameOverWindow gameWin = new GameOverWindow();
                        gameWin.ShowDialog();
                    }
                    else if (gameState == (int)DBHelper.State.Lost)
                    {
                        this.GameLost(p);
                        GameOverWindow gameWin = new GameOverWindow();
                        gameWin.ShowDialog();
                    }
                }
                else
                {
                    this.RefreshGame();
                }
            }
        }
コード例 #3
0
ファイル: MainVM.cs プロジェクト: bombic94/minesweeper
        /// <summary>
        /// Reaction to right click of button.
        /// If is not marked, mark it as mine.
        /// If marked, unmark mine.
        /// </summary>
        /// <param name="param">Button representing one field in game</param>
        private void MarkUnmarkMine(object param)
        {
            int gameState = (int)DBHelper.GetGame(this.OblastID).stav; // check if you can play

            if (gameState == (int)DBHelper.State.Playing)
            {
                Button b = param as Button;
                POLE   p = b.DataContext as POLE;

                if (p.Flag == false)
                {
                    DBHelper.MarkMine(this.OblastID, p.souradnice_x, p.souradnice_y);
                    p.Flag = true;
                }
                else
                {
                    DBHelper.UnmarkMine(this.OblastID, p.souradnice_x, p.souradnice_y);
                    p.Flag = false;
                }

                this.RefreshGame();
            }
        }