Package battleship.view
Class Terminal
java.lang.Object
battleship.view.AbstractView
battleship.view.Terminal
- All Implemented Interfaces:
View
public class Terminal extends AbstractView
Terminal view, instanced if argument 2 equals to "nogui"
- See Also:
View,AbstractView
-
Field Summary
Fields Modifier and Type Field Description private TerminalKeyboardListenerkeyboardComponentstatic java.util.ScannerscannerFields inherited from class battleship.view.AbstractView
game -
Constructor Summary
-
Method Summary
Modifier and Type Method Description Pair<java.lang.Integer,java.lang.Integer>chooseMove(Player player)ask player to choose a coords on its opponent grid, callAbstractView.chooseMove(Player)if instance of player isComputerifplayerisn'tHumaninstancevoiddisplayBoard()print board in terminalvoiddisplayWinner(Player winner)print grid, winner player and close scanner, game automatically close after thisprotected java.lang.StringgetKeyInput()ask player for keyboard input and return resultprotected java.lang.StringkeyboardInput()askGame.currentPlayerfor keyboard inputprotected intkeyboardInputInteger()protected Pair<java.lang.Integer,java.lang.Integer>mouseInput(Player player)Never call in TerminalvoidsetShips(Player player)Askplayerto set position of its shipsprotected voidsetUpperText(java.lang.String s)print stringMethods inherited from class battleship.view.AbstractView
getDirectionFromChar, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
scanner
public static java.util.Scanner scanner -
keyboardComponent
-
-
Constructor Details
-
Terminal
-
-
Method Details
-
getKeyInput
protected java.lang.String getKeyInput()Description copied from class:AbstractViewask player for keyboard input and return result- Specified by:
getKeyInputin classAbstractView- Returns:
- given string in terminal
-
setUpperText
protected void setUpperText(java.lang.String s)print string- Specified by:
setUpperTextin classAbstractView- Parameters:
s- text to display- See Also:
Window.setUpperText(String),setUpperText(String)
-
setShips
Askplayerto set position of its ships- Specified by:
setShipsin interfaceView- Overrides:
setShipsin classAbstractView- Parameters:
player- player we ask to set position of its ships- Throws:
java.lang.InterruptedException- seeAbstractView.getDirectionFromChar()
-
displayBoard
public void displayBoard()print board in terminal -
chooseMove
public Pair<java.lang.Integer,java.lang.Integer> chooseMove(Player player) throws java.lang.InterruptedExceptionask player to choose a coords on its opponent grid, callAbstractView.chooseMove(Player)if instance of player isComputerifplayerisn'tHumaninstance- Specified by:
chooseMovein interfaceView- Overrides:
chooseMovein classAbstractView- Parameters:
player-Game.currentPlayer- Returns:
- a element containing the x and y coordinate (left side store Y and right side X)
- Throws:
java.lang.InterruptedException- seeAbstractView.chooseMove(Player)
-
mouseInput
Never call in Terminal- Specified by:
mouseInputin classAbstractView- Parameters:
player-Game.currentPlayer- Returns:
null- See Also:
Window.mouseInput(Player)
-
keyboardInput
protected java.lang.String keyboardInput()Description copied from class:AbstractViewaskGame.currentPlayerfor keyboard input- Specified by:
keyboardInputin classAbstractView- Returns:
- given string in terminal
- See Also:
TerminalKeyboardListener.keyboardInput()
-
keyboardInputInteger
protected int keyboardInputInteger() throws java.lang.NumberFormatException- Returns:
- convert string from keyboardInput() and convert it into an integer
- Throws:
java.lang.NumberFormatException- if given string can't be parse into an integer- See Also:
keyboardInput()
-
displayWinner
print grid, winner player and close scanner, game automatically close after this- Parameters:
winner- the winner of the game.- See Also:
Window.displayWinner(Player),displayWinner(Player)
-