Sha256: 7e0b31a7a14539091621690408c77f55e9ed3dd0658475b55f75affab571d8d1

Contents?: true

Size: 804 Bytes

Versions: 4

Compression:

Stored size: 804 Bytes

Contents

require "./lib/game.rb"

module Codebreaker
  class Console

  def initialize
    @game = Game.new
  end
    
  def play
    puts "You have #{Game::ATTEMPS} attemps and #{Game::HINT} hint.
    Enter 'hint' for get hint. And 'exit' for exit from a game."
  
    until @game.loose?
      case code = gets.chomp
        when 'hint'
        puts "The hint is #{ @game.get_hint }"
        when 'exit'
        exit
        when /^[1-6]{4}$/
        puts @game.match_guess(code)
      end
      break if @game.win?
    end
    
    save
    @game = Game.new if try_again?
    play
  end  
    
  def try_again?
    puts 'Do you want try again?(y/n)'
    gets.chomp == 'y' ? true : exit
  end
  
  def save
    puts 'Enter your name:'
    user_name = gets.chomp
    @game.save_stat( user_name )
  end  
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
edlvj_codebreaker-0.2.2 lib/console.rb
edlvj_codebreaker-0.2.1 lib/console.rb
edlvj_codebreaker-0.2.0 lib/console.rb
edlvj_codebreaker-0.1.0 lib/console.rb