Class SimpleUI

java.lang.Object
  extended by SimpleUI
All Implemented Interfaces:
HangmanUI, java.util.Observer

public class SimpleUI
extends java.lang.Object
implements HangmanUI

Default User interface for the Hangman game. Provides a console-based user interface. Obtains user guesses from the keyboard and displays a very simplistic view of the board.


Field Summary
private  java.util.Scanner console
          input stream for the keyboard
private  Controller controller
           
private  java.lang.Readable inputSource
           
 
Constructor Summary
SimpleUI()
          Construct this user interface.
 
Method Summary
private  char getMove()
          Asks the user for a move until the user enters a move that is valid.
 void playAgain()
          Handle end of game, asking if the player wants another game If yes, start a new game, otherwise exit.
 void setControl(Controller ctrl)
          Make the interface visible
 void setReadable(java.lang.Readable rdr)
          Provide an input source for this user interface.
 void setVisible(boolean visible)
          The main event loop
 void showBoard(Game game)
          Display the current state of the board.
 void showLose(java.lang.String message)
          Display that the player lost the game.
 void showWin()
          Display that the player won the game.
 void update(java.util.Observable o, java.lang.Object arg)
          Update the ui when notified by the game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controller

private Controller controller

console

private java.util.Scanner console
input stream for the keyboard


inputSource

private java.lang.Readable inputSource
Constructor Detail

SimpleUI

public SimpleUI()
Construct this user interface.

Method Detail

setReadable

public void setReadable(java.lang.Readable rdr)
Provide an input source for this user interface.

Parameters:
rdr - a Readable from which to obtain the input.

setControl

public void setControl(Controller ctrl)
Make the interface visible

Specified by:
setControl in interface HangmanUI
Parameters:
ctrl - the controller for this view

setVisible

public void setVisible(boolean visible)
The main event loop

Specified by:
setVisible in interface HangmanUI
Parameters:
visible - unused

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Update the ui when notified by the game.

Specified by:
update in interface HangmanUI
Specified by:
update in interface java.util.Observer
Parameters:
o - which observable notified us
arg - an object passed from the observable

showBoard

public void showBoard(Game game)
Display the current state of the board. Specifically, display the turn counter and display the board in some formatted manner.

Parameters:
game - the game we are observing

getMove

private char getMove()
Asks the user for a move until the user enters a move that is valid.


showWin

public void showWin()
Display that the player won the game.

Specified by:
showWin in interface HangmanUI

showLose

public void showLose(java.lang.String message)
Display that the player lost the game. Reveal the solution.

Specified by:
showLose in interface HangmanUI
Parameters:
message - the correct solution to the puzzle

playAgain

public void playAgain()
Handle end of game, asking if the player wants another game If yes, start a new game, otherwise exit.

Specified by:
playAgain in interface HangmanUI