![]() ![]() The puzzle is solved if none of the cells have ![]() WRONG_GUESS // need to guess - wrong guess TO_GUESS, // need to guess - not attempted yetĬORRECT_GUESS, // need to guess - correct guess * An enumeration of constants to represent the status Save the file as " CellStatus.java" just like a class. We define an enum called CellStatus as follows (in Eclipse File ⇒ New ⇒ Enum). Instead of using a string (such as "correct-guess", "wrong-guess", "to-guess") or an int (1 for correct, 2 for wrong, 3 for to-guess) to represent the status of a cell, JDK 5 introduces a feature known as enumeration ( enum) to efficiently maintain a set of constants in a type-safe manner. } The CellStatus Enumeration ( enum) of Constants Public static final int SUBGRID_SIZE = 3 * Define the named constants used in many classes. To refer to these static constants, use SudokuConstants.GRID_SIZE. This class defines the named constants used by many classes, e.g. If you are using JDK/TextEditor, create a sub-directory called sudoku and place the classes under the sub-directory.You can then create the classes under the sudoku package. In Eclipse/NetNeans/VSCode, first create a "Java Project" called "sudoku" then create a new package (new ⇒ package) also called sudoku.The method newPuzzle() can be used to generate a new puzzle for a new game.Īll the classes are kept in a package called sudoku. Puzzle: A class called Puzzle is designed to model the number puzzle, which holds the numbers and clues in 9x9 int array numbers and boolean array isGiven.SudokuMain: We further customize the JFrame, by creating a subclass called SudokuMain, to hold the GameBoardPanel ( JPanel) in its ContentPane.Similar to Cell, the GameBoardPanel has its own methods to paint() itself. GameBoardPanel: We also customize the JPanel, by creating a subclass called GameBoardPanel, to hold the grid of 9x9 Cells ( JTextFields).CellStatus: An enumeration ( enum) called CellStatus is designed to hold the status constants, including GIVEN, CORRECT_GUESS, WRONG_GUESS and TO_GUESS.The Cell has its own methods to paint() itself. Cell: We customize the JTextField, by creating a subclass called Cell, with additional variables row, col, number and status, to model each cell of the grid. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |