Java Reference
In-Depth Information
56.
System.out.println(conf2.toString());
57.
System.out.println(conf1.toString());
58.
passed = false ;
59.
}
60.
}
61.
}
The listing below shows the test result as it is displayed on the console. It is
correctly detected that the second move is illegal.
Configuration ok:
1234
5678
9101112
13 14 15
0
Move 15 right
Configuration ok:
1234
5678
9101112
13 14
0 15
Move 5 up
Illegal Move!
Configuration ok:
1234
5678
9101112
13 14
0 15
Test passed
14.3
The view part
Once the model is implemented and tested, one can begin to design the display
of the game. The layout we have chosen consists of two panels embedded side by
side into a frame. The left one displays the current configuration of the board. The
right one allows a direction to be selected for a move. The appearance is shown
in Figure 14.2.
We begin by describing class BlockPuzzlePanel which displays the board. In
the constructor, the panel receives a reference to the board model it has to display.
By querying the board model it determines the number of rows and columns to
display.
As usual, the painting is done by overriding method paintComponent . Here,
the current configuration from the BoardModel is fetched. Then one queries the
Search WWH ::




Custom Search