|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectSimpleUI
public class SimpleUI
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 |
|---|
private Controller controller
private java.util.Scanner console
private java.lang.Readable inputSource
| Constructor Detail |
|---|
public SimpleUI()
| Method Detail |
|---|
public void setReadable(java.lang.Readable rdr)
rdr - a Readable from which to obtain the input.public void setControl(Controller ctrl)
setControl in interface HangmanUIctrl - the controller for this viewpublic void setVisible(boolean visible)
setVisible in interface HangmanUIvisible - unused
public void update(java.util.Observable o,
java.lang.Object arg)
update in interface HangmanUIupdate in interface java.util.Observero - which observable notified usarg - an object passed from the observablepublic void showBoard(Game game)
game - the game we are observingprivate char getMove()
public void showWin()
showWin in interface HangmanUIpublic void showLose(java.lang.String message)
showLose in interface HangmanUImessage - the correct solution to the puzzlepublic void playAgain()
playAgain in interface HangmanUI
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||