コード例 #1
0
 public GameModel(int difficulty)
 {
     Difficulty   = difficulty;
     flg.ImageUrl = "~/Images/checkered_flag.bmp";
     bmb.ImageUrl = "~/Images/bomb.bmp";
     brdSize      = Difficulty * 7;
     if (!myBoard.InPlay || myBoard == null)
     {
         myBoard = new BoardModel(brdSize, Difficulty);
     }
     Initialize(difficulty);
 }
コード例 #2
0
 public BoardModel Initialize(int difficulty)
 {
     Difficulty   = difficulty;
     flg.ImageUrl = "~/Images/checkered_flag.bmp";
     bmb.ImageUrl = "~/Images/bomb.bmp";
     brdSize      = Difficulty * 7;
     if (!myBoard.InPlay)
     {
         myBoard = new BoardModel(brdSize, Difficulty);
     }
     buttons = myBoard.ConvertGridtoList();
     return(myBoard);
 }
コード例 #3
0
        public BoardModel OnButtonClick(int BoardButtons)
        {
            if (!myBoard.inPlay)
            {
                myBoard = new BoardModel(brdSize, Difficulty);
            }
            buttons = myBoard.ConvertGridtoList();
            int cnt = BoardButtons;

            for (int rw = 0; rw < brdSize; rw++)
            {
                for (int cl = 0; cl < brdSize; cl++)
                {
                    if (myBoard.grid[rw, cl].countValue == buttons[cnt].countValue)
                    {
                        myBoard.grid[rw, cl].visited = true;
                        if (myBoard.grid[rw, cl].live)
                        {
                            myBoard.grid[rw, cl].Image = bmb;
                            isWon          = true;
                            myBoard.inPlay = false;
                            //MessageBox.Show("You hit a Mine! Length of play was: "+watch.Elapsed);
                        }
                        else
                        {
                            if (myBoard.grid[rw, cl].liveNeighbors == 0 && !myBoard.grid[rw, cl].live)
                            {
                                myBoard.grid[rw, cl].Image = flg;
                                isWon = false;
                                watch.Stop();
                                myBoard.CheckSurround(rw, cl);
                            }
                            myBoard.grid[rw, cl].visited = true;
                        }
                    }
                }
            }
            buttons = myBoard.ConvertGridtoList();
            if (isWon)
            {
                watch.Stop();
                myBoard.ShowAll();
                //MessageBox.Show("You Won! Length of play was: "+watch.Elapsed);
            }
            myBoard.UpdateButtonLabels();
            return(myBoard);
        }