|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.eriksilkensen.sudoku.SudokuModel
public class SudokuModel
SudokuModel is the Model component in the M-V-C framework and so behaves like one would expect of a Model.
It has no knowledge of the View of Control, and so only has to provide for its implementation of the Sudoku 'Model.' This includes the logic of the gameplay - which is mostly just reacting to changes to the Board that a user might make.
SudokuModel is Observable, so Observers can register themselves with it and be notified via notifyObservers() -> update() when necessary.
| Field Summary | |
|---|---|
static int |
IDLE
|
static int |
LOST
|
static int |
PLAYING
|
static int |
WON
|
| Constructor Summary | |
|---|---|
SudokuModel()
The only constructor needed for the Model, which doesn't require any parameters. |
|
| Method Summary | |
|---|---|
void |
addHints()
Since a Hint is simply a random Cell from the Board that hasn't already been solved for, addHints() just adds all "Hints" to the list of Hints |
boolean |
boardHasHints()
Not terribly useful, but still will check for any remaining Hints |
void |
checkBoard()
Checks the current board for any mistakes, populates an int[] with the coordinates of all the incorrectly placed Cells, and then notifies all Observers |
void |
checkForBestTimes()
checkForBestTimes() checks for the possibility that the user is eligible for a Best Time. |
void |
clear()
Clears all of the user's placed Cells on the board, resets the Hints, and then notifies all Observers |
void |
clearBestTimeAllowed()
Sets the bestTimeAllowed boolean to False |
void |
clearChanged()
Sets the changed boolean to False |
void |
clearStatsAllowed()
Sets the statsAllowed boolean to False |
void |
clearTimes()
Simply clears all Best Times |
void |
gameWon()
gameWon() is called when, as one might predict, a game has been won. |
java.util.ArrayList<BestTime> |
getBestTimes()
Returns the current list of Best Times |
Board |
getBoard()
Returns the current board |
int |
getBoardID()
Returns the ID number of the current Board. |
boolean |
getCellType(int row,
int col)
Returns the type of the Cell at the position [row][col] |
int |
getCellValue(int row,
int col)
Returns the value of the Cell at the position [row][col] |
BoardDifficulties |
getDifficulty()
Returns the current difficulty level |
int |
getIDLimit()
Returns the highest possible legal ID |
java.lang.String |
getRange()
Returns a String representation of the current range of legal Board ID numbers |
Board |
getSolution()
Returns the current board's solution |
int |
getStatus()
Returns the current status |
Hint |
giveHint()
Hands over a Hint to whoever asks for one. |
void |
giveUp()
Self-explanatory. |
void |
initialize()
|
boolean |
isLegal(int row,
int col)
Returns whether or not it is legal for a user to try to place a Cell at the given location [row][col] on the Board |
boolean |
isLegalID(int ID)
Helper method to determine the legality of a candidate ID number |
void |
newDownloadedGame()
Starts a new game by downloading a random Board from the internet. |
void |
newGame(Board board)
Starts a new game using the supplied Board. |
void |
newGame(BoardDifficulties difficulty)
The first of three newGame() implementations. |
void |
newGame(int ID)
Starts a new game using the specified ID to decide which Board to load. |
void |
notifyObservers()
Notifies all Observers. |
void |
printBoard()
Prints the current Board |
void |
printSolution()
Prints the current Solution |
void |
registerObserver(Observer observer)
Registers the observer with this Observable's list of Observers. |
void |
removeObserver(Observer observer)
Removes the observer from this Observable's list of Observers |
java.lang.String |
requestName()
The weird part to this method is that it will only return the name of the first Observer in the list. |
void |
setBestTimeAllowed()
Sets the bestTimeAllowed boolean to True |
void |
setChanged()
Sets the changed boolean to True |
void |
setDifficulty(BoardDifficulties difficulty)
Sets the current difficulty level |
void |
setStatsAllowed()
Sets the statsAllowed boolean to True |
void |
setStatusIdle()
Sets the status of this Model to IDLE. |
void |
setStatusPlaying()
Sets the status of this Model to PLAYING. |
void |
setTime(int time)
Sets the time |
void |
submitBestTimes()
Submits the BestTimes at the current difficulty level to the internet and updates the list of BestTimes at the JSudoku website. |
void |
updateBoard(int row,
int col,
Cell cell)
Updates the Cell at the location [row][col] and sets it to the passed Cell argument |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PLAYING
public static final int WON
public static final int LOST
public static final int IDLE
| Constructor Detail |
|---|
public SudokuModel()
| Method Detail |
|---|
public void initialize()
public void newGame(BoardDifficulties difficulty)
public void newGame(int ID)
public void newGame(Board board)
public void newDownloadedGame()
throws java.lang.Exception
java.lang.Exceptionpublic void clearTimes()
public void setTime(int time)
public void registerObserver(Observer observer)
registerObserver in interface Observablepublic void removeObserver(Observer observer)
removeObserver in interface Observablepublic void notifyObservers()
If changed is true, pass the Observer the board. Otherwise pass it the locations of all wrong Cells. A better way to solve this problem would probably be to not push everything to the Observers and instead allow them access to the changed flag and assume they can pull whatever they want from this Observable.
notifyObservers in interface Observablepublic void gameWon()
public void checkForBestTimes()
public void submitBestTimes()
throws java.net.MalformedURLException,
com.jcraft.jsch.JSchException,
java.io.IOException
java.net.MalformedURLException
com.jcraft.jsch.JSchException
java.io.IOExceptionpublic void giveUp()
public Hint giveHint()
public void addHints()
public boolean boardHasHints()
public java.util.ArrayList<BestTime> getBestTimes()
public java.lang.String requestName()
public void updateBoard(int row,
int col,
Cell cell)
public void clear()
public void setDifficulty(BoardDifficulties difficulty)
public BoardDifficulties getDifficulty()
public Board getBoard()
public Board getSolution()
public int getStatus()
public void setStatusIdle()
public void setStatusPlaying()
public boolean isLegalID(int ID)
public java.lang.String getRange()
public int getIDLimit()
public void checkBoard()
public boolean getCellType(int row,
int col)
public int getCellValue(int row,
int col)
public int getBoardID()
public boolean isLegal(int row,
int col)
public void setChanged()
public void clearChanged()
public void setBestTimeAllowed()
public void clearBestTimeAllowed()
public void setStatsAllowed()
public void clearStatsAllowed()
public void printBoard()
throws java.lang.Exception
java.lang.Exception
public void printSolution()
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||