Skip to content

Commit

Permalink
Adds handling of UnsupportedCommandError, InvalidCommandParametersErr…
Browse files Browse the repository at this point in the history
…or and ExplosionError exceptions in the game loop.
  • Loading branch information
sebastienatplumbee committed Jun 8, 2015
1 parent 372249a commit 34cfc3f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/minesweeper/console/game_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require_relative 'parser/command_parser'
require_relative 'mine_layer'
require_relative 'mine_coordinates_factory'
require_relative 'parser/unsupported_command_error'
require_relative 'parser/invalid_command_parameters_error'

module Minesweeper
module Console
Expand All @@ -22,9 +24,16 @@ def initialize(size)
def start
@mine_layer.lay(@row_count)
loop do
begin
puts @pretty_printer.print
user_input = Readline.readline(PROMPT, true)
@command_parser.parse(user_input).execute
rescue Parser::UnsupportedCommandError, Parser::InvalidCommandParametersError => e
puts e.message
rescue Minesweeper::Explosives::ExplosionError => e
puts e.message
exit
end
end
end

Expand Down

0 comments on commit 34cfc3f

Please sign in to comment.