Java Reference
In-Depth Information
Next comes the call to the returnGridSequence() function, which converts the
grid into a JavaFX Integer sequence:
/*
* convert results to a format suitable for JavaFX
*/
var puzzle : Integer[] = sudokuGrid.returnGridSequence();
The rest of the function contains code necessary to translate the contents of each
cell. Inside grid , the way in which state is stored is fairly similar to the way it's
done with JavaFX Sudoku. Instead of using number values that are multiples of
10, the author(s) used bitmasks to store multiple values in each cell. Listing 13.2
shows the newPuzzle() function.
Listing 13.2
The newPuzzle() Function
/*
* Use the SudokuGenerator code found at
* sourceforge.net to create a new Puzzle. Written
* in Java, the SudokuGenerator requires a small
* amount of translation code to move the data
* structure over to a suitable JavaFX form.
* The sudokuGrid.returnGridSequence() method performs
* that task.
*
* Arguments:
* numHints: Determines the Number of initial spaces
* (hints) that will be displayed at
* startup. The larger this number is,
*
the easier the puzzle is to solve.
*/
public function newPuzzle(numHints : Integer) : Void {
/*
* Call SudokuGenerator Java code to generate
* a new puzzle.
*/
var sudokuGenerator : SudokuGenerator =
new SudokuGenerator();
sudokuGenerator.generatePuzzle(numHints,
GV.NumDistributuon.random );
var sudokuGrid : SudokuGrid =
sudokuGenerator.getGrid();
/*
* convert results to a format suitable for JavaFX
*/
var puzzle : Integer[] =
sudokuGrid.returnGridSequence();
continues
Search WWH ::




Custom Search