Class PuzzleBoard
java.lang.Object
|
+----PuzzleBoard
- public class PuzzleBoard
- extends Object
-
PuzzleBoard()
-
The default constructor-- sets up the board of puzzlePieces
-
draw()
- Draws the board and the "Scramble" box.
-
isScramble(Point)
- Given a point, checks if it's inside the "Scramble" box.
-
move(Point)
- Takes the point p and checks if it is within the "Scramble"
box.
-
privateMove(int, int)
- Takes the indices and checks for the place to move the piece.
-
Scramble()
- Scrambles the pieces by calling privateMove a 1000 times
with randomly generated indices.
PuzzleBoard
public PuzzleBoard()
- The default constructor-- sets up the board of puzzlePieces
move
public void move(Point p)
- Takes the point p and checks if it is within the "Scramble"
box. If so, it calls the private method Scramble().
If not, it determines which square has been clicked (in terms
of the indices of the array) and calls a private method
privateMove with the indices.
- Parameters:
- p - the location of the last mouse click
draw
public void draw()
- Draws the board and the "Scramble" box.
The puzzle pieces are drawn by calling the draw method
in PuzzlePiece.
isScramble
private boolean isScramble(Point p)
- Given a point, checks if it's inside the "Scramble" box.
- Parameters:
- p - the point the user clicked.
- Returns:
- true if p is in the box, false otherwise.
Scramble
private void Scramble()
- Scrambles the pieces by calling privateMove a 1000 times
with randomly generated indices.
(This is called from move().).
privateMove
private void privateMove(int i,
int j)
- Takes the indices and checks for the place to move the piece.
This is where all the work takes place. After finding the move,
the piece is moved to it's new position in the array, and it's
position on the board is updated using the move method in
PuzzlePiece.
- Parameters:
- i - the first index, ranges from 0 to 3
- j - the second index, ranges from 0 to 3