//marks all mines with an X public void SetFail(ref MineModel board) { for (int row = 0; row < board.Size; row++) { for (int col = 0; col < board.Size; col++) { if (board.Buttons[row, col].isMine) { board.Buttons[row, col].Text = "X"; } } } }
//primary game loop private void RunGame() { //build and display dialogue to choose board size fail = false; view = new MineView(); Form sizeForm = new Form(); TableLayoutPanel sizePanel = view.ChooseSize(); foreach (Control c in sizePanel.Controls) { c.Click += new EventHandler(SizeClick); } sizeForm.Size = new Size(300, 100); sizeForm.Controls.Add(sizePanel); sizeForm.ShowDialog(); sizeForm.Dispose(); //build and display dialogue to choose difficulty Form difForm = new Form(); TableLayoutPanel difPanel = view.ChooseDif(); foreach (Control c in difPanel.Controls) { c.Click += new EventHandler(DifClick); } difForm.Size = new Size(300, 100); difForm.Controls.Add(difPanel); difForm.ShowDialog(); difForm.Dispose(); //build and display main game board board = new MineModel(size, freq); Form gameBoard = new Form(); //create the parent region to hold the rest of the game controls TableLayoutPanel parent = new TableLayoutPanel(); parent.Dock = DockStyle.Fill; parent.RowCount = 2; parent.ColumnCount = 3; parent.RowStyles.Add(new RowStyle(SizeType.Absolute, 60)); parent.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); parent.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.33F)); parent.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.33F)); parent.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.33F)); //create and register the new game button Button newGame = new Button(); newGame.Dock = DockStyle.Fill; newGame.Text = "New Game"; newGame.Click += new EventHandler(NewClick); parent.Controls.Add(newGame, 0, 0); //create and register smiley face smiley = new Button(); smiley.Dock = DockStyle.Fill; smiley.Font = new Font(smiley.Font.FontFamily, 25); smiley.Text = ":D"; parent.Controls.Add(smiley, 1, 0); //create and register the number of mines display mineCount = new Button(); mineCount.Dock = DockStyle.Fill; mineCount.Text = board.Nummines.ToString(); parent.Controls.Add(mineCount, 2, 0); //create and add the panel with the mine buttons, and add their event listeners TableLayoutPanel gamePanel = view.GameRegion(board.Buttons); foreach (Control c in gamePanel.Controls) { c.Click += new EventHandler(GameClick); c.MouseUp += new MouseEventHandler(GameRightClick); } //finalize appearance and display form gameBoard.Size = new Size(600, 600); parent.SetColumnSpan(gamePanel, 3); parent.Controls.Add(gamePanel, 0, 1); gameBoard.Controls.Add(parent); gameBoard.ShowDialog(); }