Class: MasterMind::Tobi::GameHelper
- Inherits:
-
Object
- Object
- MasterMind::Tobi::GameHelper
- Defined in:
- lib/mastermind/tobi/gamehelper.rb
Instance Method Summary collapse
- #ask_level ⇒ Object
- #ask_mode(sequence, game_logic) ⇒ Object
- #play_game ⇒ Object
- #print_help ⇒ Object
- #user_choice ⇒ Object
- #validate_input?(input) ⇒ Boolean
Instance Method Details
#ask_level ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 68 def ask_level print UI::LEVEL_MESSAGE option_chosen = false while !option_chosen option_chosen = true # assume user selects valid level so as to quit loop input = gets.chomp.downcase case input when "b", "beginner" then return GameLogic::BEGINNER when "i", "intermediate" then return GameLogic::INTERMEDIATE when "a", "advanced" then return GameLogic::ADVANCED else # user selects an invalid level print UI::INVALID_MESSAGE option_chosen = false end end end |
#ask_mode(sequence, game_logic) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 41 def ask_mode(sequence, game_logic) print UI::MODE_SELECT option_chosen = false while !option_chosen option_chosen = true # assume user selects valid option so as to quit loop input = gets.chomp.downcase case input when "s", "single" then SinglePlayer.new(sequence, game_logic).start_game when "m", "multi" print UI::PASSWORD_MESSAGE hide_guess = MasterMind::Tobi::GameMethods.new.yes_or_no? MultiPlayer.new(sequence, game_logic, hide_guess).start_game else print UI::INVALID_MESSAGE option_chosen = false end end end |
#play_game ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 33 def play_game game_logic = GameLogic.new(ask_level); sequence = game_logic.generate_sequence ask_mode(sequence, game_logic) puts "" print UI::OPTIONS_MESSAGE + UI::INPUT_PROMPT user_choice end |
#print_help ⇒ Object
63 64 65 66 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 63 def print_help puts UI::HELP_MESSAGE print UI::OPTIONS_MESSAGE + UI::INPUT_PROMPT end |
#user_choice ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 9 def user_choice option_chosen = false while !option_chosen option_chosen = true # assume user selects valid option so as to quit loop input = gets.chomp.downcase option_chosen = validate_input?(input) end end |
#validate_input?(input) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mastermind/tobi/gamehelper.rb', line 20 def validate_input?(input) case input when "p", "play" then play_game when "r", "read" print_help return false # continue loop after displaying help message when "q", "quit" then exit else # user selects an invalid option print UI::INVALID_MESSAGE return false end end |