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 TerminalKeyboardListener
keyboardComponent
static java.util.Scanner
scanner
Fields 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 isComputer
ifplayer
isn'tHuman
instancevoid
displayBoard()
print board in terminalvoid
displayWinner(Player winner)
print grid, winner player and close scanner, game automatically close after thisprotected java.lang.String
getKeyInput()
ask player for keyboard input and return resultprotected java.lang.String
keyboardInput()
askGame.currentPlayer
for keyboard inputprotected int
keyboardInputInteger()
protected Pair<java.lang.Integer,java.lang.Integer>
mouseInput(Player player)
Never call in Terminalvoid
setShips(Player player)
Askplayer
to set position of its shipsprotected void
setUpperText(java.lang.String s)
print stringMethods inherited from class battleship.view.AbstractView
getDirectionFromChar, toString, toString
Methods 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:AbstractView
ask player for keyboard input and return result- Specified by:
getKeyInput
in classAbstractView
- Returns:
- given string in terminal
-
setUpperText
protected void setUpperText(java.lang.String s)print string- Specified by:
setUpperText
in classAbstractView
- Parameters:
s
- text to display- See Also:
Window.setUpperText(String)
,setUpperText(String)
-
setShips
Askplayer
to set position of its ships- Specified by:
setShips
in interfaceView
- Overrides:
setShips
in 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 isComputer
ifplayer
isn'tHuman
instance- Specified by:
chooseMove
in interfaceView
- Overrides:
chooseMove
in 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:
mouseInput
in classAbstractView
- Parameters:
player
-Game.currentPlayer
- Returns:
null
- See Also:
Window.mouseInput(Player)
-
keyboardInput
protected java.lang.String keyboardInput()Description copied from class:AbstractView
askGame.currentPlayer
for keyboard input- Specified by:
keyboardInput
in 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)
-