Class: BattleBoats::ConsoleUI
- Inherits:
-
Object
- Object
- BattleBoats::ConsoleUI
- Defined in:
- lib/battle_boats/console_ui.rb
Instance Method Summary collapse
- #display_board(board) ⇒ Object
- #display_errors(errors) ⇒ Object
- #display_status_report(status_report) ⇒ Object
- #get_coordinate ⇒ Object
- #greet ⇒ Object
-
#initialize(output: $stdout, input: $stdin) ⇒ ConsoleUI
constructor
A new instance of ConsoleUI.
Constructor Details
#initialize(output: $stdout, input: $stdin) ⇒ ConsoleUI
Returns a new instance of ConsoleUI.
5 6 7 8 |
# File 'lib/battle_boats/console_ui.rb', line 5 def initialize(output: $stdout, input: $stdin) @output = output @input = input end |
Instance Method Details
#display_board(board) ⇒ Object
14 15 16 |
# File 'lib/battle_boats/console_ui.rb', line 14 def display_board(board) output.puts format_board(board) end |
#display_errors(errors) ⇒ Object
32 33 34 |
# File 'lib/battle_boats/console_ui.rb', line 32 def display_errors(errors) output.puts errors end |
#display_status_report(status_report) ⇒ Object
28 29 30 |
# File 'lib/battle_boats/console_ui.rb', line 28 def display_status_report(status_report) output.puts status_report end |
#get_coordinate ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/battle_boats/console_ui.rb', line 18 def get_coordinate output.puts "Target coordinate: " user_input = input.gets.chomp until valid_input?(user_input) output.puts "Coordinate invalid." user_input = input.gets.chomp end input_to_coordinate(user_input) end |
#greet ⇒ Object
10 11 12 |
# File 'lib/battle_boats/console_ui.rb', line 10 def greet output.puts "Welcome to Battle Boats!" end |