Sha256: 8991c57f2524ba6a094c87f3577c50b141e0188f995c74ce9c15070e0d864ddb
Contents?: true
Size: 833 Bytes
Versions: 3
Compression:
Stored size: 833 Bytes
Contents
class Console def start catch :finish do loop do @game = Codebreaker::Game.new round save_game_result try_again end end end def round until @game.ended? print 'Your guess: ' input = gets.to_s.strip input == 'hint' ? use_hint : guess(input) end puts "The round is over, you #{@game.winner? ? 'won' : 'loose'}!" end def guess(input) puts @game.guess(input) || 'Incorrect input!' end def use_hint puts @game.hint || 'All hints are used!' end def save_game_result print 'Do you want to save result? (y/n): ' @game.save if confirmation end def try_again print 'Do you want to try again? (y/n): ' throw :finish unless confirmation end def confirmation gets.to_s.strip.casecmp('y').zero? end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
codebreaker_z-1.2.0 | lib/codebreaker/console.rb |
codebreaker_z-1.1.0 | lib/codebreaker/console.rb |
codebreaker_z-1.0.0 | lib/codebreaker/console.rb |