Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, would somebody be able to help me out with this? I have the board displayed currently, but thats about it. Create a Java JFrame

Hi, would somebody be able to help me out with this? I have the board displayed currently, but thats about it. image text in transcribed
image text in transcribed
Create a Java JFrame window application to play the Mine Sweeper game. The JFrame window you create should use the BorderLayout manager and in the center region use a panel with the GridLayout layout manager to display an n by n grid of buttons. When the game is started, input the value of n using a JOptionPane.showlnputDialog message box before making the game window Extend the JButton class to create a new class called MineButton. Add a boolean member variables to this class to indicate if the square is a mine and it the square has been tested and exposed (stepped on). Randomly select about 10%-15% of the squares to be the mines or you could input the percentage of squares to be mines or input the number of mines. Add a two dimensional array of these buttons, one for each square on the board. In each button, its mine will have a true value if the square is a mine and a false value for the safe squares variable Initially, all the buttons will display blank text and should have a grey (null) background color. If a button is clicked that is a mine, the text in the button should be changed to an X, its background color should be changed to red along with the background color of all mine squares and a JOptionPane message box should pop up saying that the game is over. If a button is clicked that is not a mine, the background color of that button should be changed to light blue. If there are no mine squares bordering the clicked square, the text in the square should be blank. Otherwise, the text in the square should display the number of mines touching the square. If the square has no mines adjacent to it, the adjacent squares should be exposed and the text in each of the surrounding buttons should be changed to a number between 1 and 8 indicating the number of mines touching that square. The text for a square that does not border a mine should remain blank. At the top of the window, a JLabel and JTextField should be displayed. The text field should show the number of mines on the board. As mines are marked, a count should be decremented and displayed in the text field Use a MouseListener instead of an ActionListener with each button so that you can determine whether the left or right mouse button has been clicked. If the right mouse button is clicked on a square, the player is stepping on that square and the game is over if it is a mine. Otherwise, the square should be exposed. If the right mouse button is clicked, the mine should be marked by turning the background color to yellow and putting the text "" on the button. This marks the button as a mine even if it is not one and the remaining mines count should be decremented. If a flagged square is right clicked again, it should be set back as an unexposed square and the remaining mines count should be incremented. When all non-mine squares have been found, a pop up box saying that "YOU WIN" should be displayed. When the box is dismissed, a new game should be started. When a square is found that does not border any mines, all squares around it should also be displayed. This can be performed very easily by performing a "doClick()" operation on all of its surrounding squares. However, this can be somewhat slow. You must do this without using the doClick() method. Instead use recursion to find and expose the contiguous squares that have no mines adjacent to them around the original node that was first clicked

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions