Random class
to randomly place the mines.
.java
file (as an attachment) with the URL of your finished applet to mrsimon@lycos.com.
Cell
that extends Button
and add three new member variables: a boolean bIsAMine
and two ints myRow and myCol
. You will need
to write some methods for Cell
as well: a constructor as well as others. (Thanks to Timmy Yee for suggesting
this hint)
actionPerformed
you can find out the row and column of the button that was pressed with code like:
int nRow = ((Cell)e.getSource()).getRow();
Cell
and the "Applet" class.
Random class
in the "Applet" class. Don't forget
import java.util.Random;
- public void init()
- public void actionPerformed(ActionEvent e)
- public void changeBackground(int nRow, int nCol) //Changes the background of a button that has been clicked normally
- public int countBombs(int nRow, int nCol) //counts the bombs in the 8 neighbors--(remember to check to see if the cell
is "on the edge")
- public void setBombs() //randomly places the bombs
- public boolean isWon() //determines if the player has won the game
- public void displayWinMessage() //uses setLabel to change the labels of the buttons to display a winning message
- public void displayLosingMessage() //displays the positions of all the bombs and displays a losing message
changeBackground
method is tricky: if the cell contains a bomb it's background should be changed to red,
otherwise it should be changed to white. If a white cell has no neighboring bombs, it should recursively call itself with the
neighboring positions that are yellow.
actionPerformed
you can check for "non-normal" clicks (e.g. shift-clicks)
with the following code:
if(e.getModifiers() != 0)