com.eriksilkensen.sudoku
Class SudokuControl

java.lang.Object
  extended by com.eriksilkensen.sudoku.SudokuControl
Direct Known Subclasses:
SudokuNetworkedControl

public class SudokuControl
extends java.lang.Object

SudokuControl is the Control component in the M-V-C framework and so behaves like one would expect of a Control

It coordinates all communication between the Model and the View, and is used to start a new game.

Since:
1.0
Version:
04/29/07
Author:
Erik Silkensen

Field Summary
protected  SudokuModel model
           
protected  SudokuView view
           
 
Constructor Summary
SudokuControl()
          Default no-arg constructor for the Control It probably will never be used
SudokuControl(SudokuModel model)
          Initializes the Control with its passed in Model and then creates the View.
 
Method Summary
 void checkBoard()
          Checks the user's Board
 void checkForBestTimes()
          Uses the Model to checkForBestTimes()
 void clear()
          Clears the Model
 void clearTimes()
          Clears the Model's Best Times
 boolean connectToNetwork(java.lang.String name)
          This Control doesn't concern itself with Network capabilities, but it still defines the methods that could be used by one that does.
 boolean disconnectFromNetwork()
          This Control doesn't concern itself with Network capabilities, but it still defines the methods that could be used by one that does.
 java.util.ArrayList<BestTime> getBestTimes()
          Returns a List of the top 5 Best Times
 Board getBoard()
          Returns the current Board in use by the Model
 int getBoardID()
          Returns the current Board's ID
 BoardDifficulties getDifficulty()
          Returns the current difficulty of the Model
protected  java.lang.String getHost()
           
 int getIDLimit()
          Used to get the limit for possible Board IDs that could be played as an integer.
protected  int getPort()
           
 java.lang.String getRange()
          Used to get the range of possible Board IDs that the user could choose from when manually selecting a Board
 Board getSolution()
          Returns the solution to the current Board in use by the Model
 int getStatus()
          Returns the current status of the Model
 void giveUp()
          Notifies the Model that the user has decided to Give Up
 void hint()
          Called by the View when a user is requesting a Hint
protected  void initGame()
          Initializes a game by setting up the View's controls
 boolean isLegalID(int ID)
          Helper method to determine if the requested ID does in fact exist
 void loadGame(java.io.File file)
          Loads a game from the selected File
 boolean newBoard()
          The no-arg version of newBoard() assumes the user is asking to enter a specific ID, so the Control gets it and passes it on to the Model If the user decides to not enter an ID, newBoard() returns false.
 void newBoard(BoardDifficulties difficulty)
          A View requests a new Board at the given difficulty, so the Model gets one and the Control starts it
 void newBoard(int ID)
          This method should only be used by the NetworkedControl in order to start a new game by passing along messages over the network.
 void newDownloadedBoard()
          This version of newBoard() downloads a Board from the internet at a random difficulty level.
 void printBoard()
          Prints the current Board
 void printSolution()
          Prints the current Solution
 void registerObserver(SudokuObserver observer)
          This Control isn't actually Observable, but it still passes along the View's request to register as an Observer with the Observable Model
 void removeObserver(SudokuObserver observer)
          Passes the View's request to remove itself from the Model's list of Observers
 void saveGame(java.io.File file)
          Saves a game to the specified File
 boolean setBoard(int row, int col, int playerValue)
          When a user places a number on the board, the Model is updated by sending the location and value of the Cell that the user placed.
protected  void setHost(java.lang.String host)
           
protected  void setPort(java.lang.String port)
           
 void setStatusIdle()
          Sets the status of the Model to be IDLE
 void setStatusPlaying()
          Sets the status of the Model to be PLAYING
 void setTime(int time)
          Sets the time
protected  void showHideChatRoom()
           
 void start()
          start() should be called from a launching (main) method in order to, right now, just show the View
 void submitTimes()
           
 void windowClosing()
          Called by the View when the user is closing its Window, so the Control can do whatever last-second things it needs to before shutting down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected SudokuModel model

view

protected SudokuView view
Constructor Detail

SudokuControl

public SudokuControl()
Default no-arg constructor for the Control It probably will never be used


SudokuControl

public SudokuControl(SudokuModel model)
Initializes the Control with its passed in Model and then creates the View.

Method Detail

registerObserver

public void registerObserver(SudokuObserver observer)
This Control isn't actually Observable, but it still passes along the View's request to register as an Observer with the Observable Model


removeObserver

public void removeObserver(SudokuObserver observer)
Passes the View's request to remove itself from the Model's list of Observers


start

public void start()
start() should be called from a launching (main) method in order to, right now, just show the View


newBoard

public void newBoard(BoardDifficulties difficulty)
A View requests a new Board at the given difficulty, so the Model gets one and the Control starts it


newBoard

public boolean newBoard()
The no-arg version of newBoard() assumes the user is asking to enter a specific ID, so the Control gets it and passes it on to the Model If the user decides to not enter an ID, newBoard() returns false.


saveGame

public void saveGame(java.io.File file)
              throws java.io.IOException
Saves a game to the specified File

Throws:
java.io.IOException

loadGame

public void loadGame(java.io.File file)
              throws java.io.IOException,
                     java.lang.ClassNotFoundException
Loads a game from the selected File

Throws:
java.io.IOException
java.lang.ClassNotFoundException

newDownloadedBoard

public void newDownloadedBoard()
This version of newBoard() downloads a Board from the internet at a random difficulty level.


newBoard

public void newBoard(int ID)
This method should only be used by the NetworkedControl in order to start a new game by passing along messages over the network. The int argument is the ID of the Board to start playing.


setHost

protected void setHost(java.lang.String host)

setPort

protected void setPort(java.lang.String port)

getHost

protected java.lang.String getHost()

getPort

protected int getPort()

showHideChatRoom

protected void showHideChatRoom()

initGame

protected void initGame()
Initializes a game by setting up the View's controls


hint

public void hint()
Called by the View when a user is requesting a Hint


setBoard

public boolean setBoard(int row,
                        int col,
                        int playerValue)
When a user places a number on the board, the Model is updated by sending the location and value of the Cell that the user placed. Since this method is called whenever a user clicks on the board, a call to the Model's isLegal() method is necessary in order to avoid placing user-cells on permanent starting cells.


clear

public void clear()
Clears the Model


clearTimes

public void clearTimes()
Clears the Model's Best Times


submitTimes

public void submitTimes()
                 throws java.net.MalformedURLException,
                        com.jcraft.jsch.JSchException,
                        java.io.IOException
Throws:
java.net.MalformedURLException
com.jcraft.jsch.JSchException
java.io.IOException

checkBoard

public void checkBoard()
Checks the user's Board


giveUp

public void giveUp()
Notifies the Model that the user has decided to Give Up


checkForBestTimes

public void checkForBestTimes()
Uses the Model to checkForBestTimes()


setStatusIdle

public void setStatusIdle()
Sets the status of the Model to be IDLE


setStatusPlaying

public void setStatusPlaying()
Sets the status of the Model to be PLAYING


getStatus

public int getStatus()
Returns the current status of the Model


getDifficulty

public BoardDifficulties getDifficulty()
Returns the current difficulty of the Model


getBoardID

public int getBoardID()
Returns the current Board's ID


setTime

public void setTime(int time)
Sets the time


getRange

public java.lang.String getRange()
Used to get the range of possible Board IDs that the user could choose from when manually selecting a Board


getIDLimit

public int getIDLimit()
Used to get the limit for possible Board IDs that could be played as an integer.


isLegalID

public boolean isLegalID(int ID)
Helper method to determine if the requested ID does in fact exist


getBestTimes

public java.util.ArrayList<BestTime> getBestTimes()
Returns a List of the top 5 Best Times


getBoard

public Board getBoard()
Returns the current Board in use by the Model


getSolution

public Board getSolution()
Returns the solution to the current Board in use by the Model


windowClosing

public void windowClosing()
Called by the View when the user is closing its Window, so the Control can do whatever last-second things it needs to before shutting down.


connectToNetwork

public boolean connectToNetwork(java.lang.String name)
This Control doesn't concern itself with Network capabilities, but it still defines the methods that could be used by one that does.


disconnectFromNetwork

public boolean disconnectFromNetwork()
This Control doesn't concern itself with Network capabilities, but it still defines the methods that could be used by one that does.


printBoard

public void printBoard()
                throws java.lang.Exception
Prints the current Board

Throws:
java.lang.Exception

printSolution

public void printSolution()
                   throws java.lang.Exception
Prints the current Solution

Throws:
java.lang.Exception