Java Reference
In-Depth Information
The Overall Design
Briefly mentioned earlier, the application has been architected such that the over-
all game logic and the user interface have been cleanly separated in a relatively
straightforward fashion. As a rule of thumb, source files suffixed with Node are
presentation or interface files, whereas those without the Node moniker are dedi-
cated to providing the logic necessary to play the Sudoku game.
The Logic
The game logic for the Sudoku application is primarily supplied by two JavaFX
classes: Board and Space . The Board class represents a Sudoku board. It has
code to interpret the rules of the game and is ultimately responsible for starting a
new game, determining if an individual move is valid, maintaining the state of
the game, and providing a solution to the puzzle.
The Board class includes a sequence of 81 Space s representing the 9u9 grid of
spaces that make up a standard Sudoku puzzle. At initialization, the Board class
identifies which row, column, and region (or box) each of the 81 Space s belong
to and groups them accordingly. Each Space has instance variables that identify
its row / column / region , and most importantly, a number variable holding the
value that is currently assigned to this space. The value of number is used to
interpret the current state of the Space . Externally, Sudoku spaces can only have
a numeric value ranging from 1-9, or be blank. Internally, the number value for a
Space instance has a larger range. Table 13.3 explains the possible values that
can be assigned to a Space 's number instance variable, and how they affect what
is ultimately displayed to the user.
Ta b l e 1 3 . 3
Range of Internal Values a number Instance Variable Can Be Assigned and How
They Are Ultimately Displayed Externally
'number'
value
Description
Appearance
0
Indicates that the space is editable and is
currently blank.
The space will be blank.
1-9
Indicates that the space is editable, and
that during play the user has entered a
valid number into the space represented
by the value.
The space will be filled in with a white
number represented by the value.
 
 
 
Search WWH ::




Custom Search