com.eriksilkensen.sudoku
Class SudokuNetworkedControl

java.lang.Object
  extended by com.eriksilkensen.sudoku.SudokuControl
      extended by com.eriksilkensen.sudoku.SudokuNetworkedControl
All Implemented Interfaces:
Observer

public class SudokuNetworkedControl
extends SudokuControl
implements Observer

SudokuNetworkedControl is an enhanced version of the default SudokuControl, and so behaves exactly like one would expect of a Control in the M-V-C framework.

NetworkedControl implements the Observer interface so that it can register itself as an Observer of the Observable Client interface. This way, any changes made to the Client (like a message being sent across the network) are brought to the attention of the listening Controls.

This would allow a multi-player game to be played over a network connection.

Since:
1.0.2
Version:
04/26/07
Author:
Erik Silkensen

Field Summary
 
Fields inherited from class com.eriksilkensen.sudoku.SudokuControl
model, view
 
Constructor Summary
SudokuNetworkedControl(SudokuModel model)
          The only constructor does everything its super class version does, and then creates a new Client and registers itself with the Client
 
Method Summary
 void checkBoard()
          Overrides checkBoard() in SudokuControl to notify the other players that this one has won.
 boolean connectToNetwork(java.lang.String name)
          Attempts to connect to the network, and returns the success of the attempt
 boolean disconnectFromNetwork()
          Attempts to disconnect from the network, and returns the success of the attempt -> false if the Client wasn't connected in the first place
protected  java.lang.String getHost()
           
protected  int getPort()
           
 void giveUp()
          Overrides giveUp() in SudokuControl to notify the other players that this one has given up.
 void newBoard(int ID)
          NetworkedControl-specific method for creating a newBoard() which sends out a message with the ID of the Board to be played
protected  void setHost(java.lang.String host)
           
protected  void setPort(java.lang.String port)
           
protected  void showHideChatRoom()
           
 void update(Observable obs, java.lang.Object arg)
          This method is called automatically by the Observable Client whenever it needs to call attention to itself.
 void windowClosing()
          Called by the View when a user is closing their window
 
Methods inherited from class com.eriksilkensen.sudoku.SudokuControl
checkForBestTimes, clear, clearTimes, getBestTimes, getBoard, getBoardID, getDifficulty, getIDLimit, getRange, getSolution, getStatus, hint, initGame, isLegalID, loadGame, newBoard, newBoard, newDownloadedBoard, printBoard, printSolution, registerObserver, removeObserver, saveGame, setBoard, setStatusIdle, setStatusPlaying, setTime, start, submitTimes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SudokuNetworkedControl

public SudokuNetworkedControl(SudokuModel model)
The only constructor does everything its super class version does, and then creates a new Client and registers itself with the Client

Method Detail

update

public void update(Observable obs,
                   java.lang.Object arg)
This method is called automatically by the Observable Client whenever it needs to call attention to itself. The NetworkedControl observes its Client, which will send out messages when it wants to start a new game or become a host, for example

The Client sends out Objects, and implements the "push" strategy by pushing along whatever arg it wants to the Observing Control, instead of forcing the Control to "pull" information from the Client. This also means, though, that the Control is responsible for doing the required casting.

Specified by:
update in interface Observer

newBoard

public void newBoard(int ID)
NetworkedControl-specific method for creating a newBoard() which sends out a message with the ID of the Board to be played

Overrides:
newBoard in class SudokuControl

giveUp

public void giveUp()
Overrides giveUp() in SudokuControl to notify the other players that this one has given up.

Overrides:
giveUp in class SudokuControl

checkBoard

public void checkBoard()
Overrides checkBoard() in SudokuControl to notify the other players that this one has won.

Overrides:
checkBoard in class SudokuControl

windowClosing

public void windowClosing()
Called by the View when a user is closing their window

Overrides:
windowClosing in class SudokuControl

connectToNetwork

public boolean connectToNetwork(java.lang.String name)
Attempts to connect to the network, and returns the success of the attempt

Overrides:
connectToNetwork in class SudokuControl

disconnectFromNetwork

public boolean disconnectFromNetwork()
Attempts to disconnect from the network, and returns the success of the attempt -> false if the Client wasn't connected in the first place

Overrides:
disconnectFromNetwork in class SudokuControl

setHost

protected void setHost(java.lang.String host)
Overrides:
setHost in class SudokuControl

setPort

protected void setPort(java.lang.String port)
Overrides:
setPort in class SudokuControl

showHideChatRoom

protected void showHideChatRoom()
Overrides:
showHideChatRoom in class SudokuControl

getHost

protected java.lang.String getHost()
Overrides:
getHost in class SudokuControl

getPort

protected int getPort()
Overrides:
getPort in class SudokuControl