Class: Codebreaker::Console
- Inherits:
-
Object
- Object
- Codebreaker::Console
- Defined in:
- lib/codebreaker/console.rb
Constant Summary collapse
- COMMANDS =
{ start: 'start', rules: 'rules', stats: 'stats', exit: 'exit' }.freeze
- HINT =
'hint'- ANSWERS =
{ yes: 'yes' }.freeze
Instance Method Summary collapse
- #hint_show ⇒ Object
- #launch ⇒ Object
- #loose ⇒ Object
- #round_game ⇒ Object
- #stats_show ⇒ Object
- #win ⇒ Object
Instance Method Details
#hint_show ⇒ Object
37 38 39 40 41 42 |
# File 'lib/codebreaker/console.rb', line 37 def hint_show return (:over_hint) if @game.hints.zero? puts @game.show_hints @game.take_hints end |
#launch ⇒ Object
16 17 18 19 20 21 |
# File 'lib/codebreaker/console.rb', line 16 def launch (:start_game) (:wel_instruct, COMMANDS) @answer = read_from_console check_answer end |
#loose ⇒ Object
51 52 53 54 |
# File 'lib/codebreaker/console.rb', line 51 def loose (:lose) continue_game? ? start_game : exit end |
#round_game ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/codebreaker/console.rb', line 23 def round_game while @game.attempts.positive? user_answer = next hint_show if user_answer == HINT next (:invalid_number) unless @game.validate_code(user_answer, Codebreaker::Game::USER_ANSWER_REX) @game.handle_guess(user_answer) return win if @game.equal_codes?(user_answer) end loose end |
#stats_show ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/codebreaker/console.rb', line 56 def stats_show @stat = Codebreaker::Statistics.new return (:empty_stat) unless data = @stat.stats (:stats) (:col_table) data.each_with_index do |row, index| print "#{index}\t" row.each do |_key, cell| print "#{cell}\t" end print "\n" end end |
#win ⇒ Object
44 45 46 47 48 49 |
# File 'lib/codebreaker/console.rb', line 44 def win (:win) (:progress) @game.save if read_from_console.eql? ANSWERS[:yes] continue_game? ? start_game : exit end |