Sha256: bb3b0146927f43242fbb1196fb8864ef603df838fec80e10384ee76159396dfa

Contents?: true

Size: 643 Bytes

Versions: 4

Compression:

Stored size: 643 Bytes

Contents

module Codebreaker
  module Console
    def input
      gets.chomp
    end

    def input_name
      print 'Please, enter your name: '
      input
    end

    def input_code
      puts "You have #{@game.attempts} attempts and #{@game.hint} hint."
      print 'Type your secret code or "hint": '
      player_code = input
      if player_code =~ /^[1-6]{4}|hint$/
        player_code
      else
        puts 'You should type 4 numbers in code or "hint"!!!'
        input_code
      end
    end

    def agree?
      input =~ /^(yes|y)$/i ? true : false
    end

    def new_game
      @game = Game.new(@game.score) if agree?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
Codebreaker_RG2016-0.2.4 lib/codebreaker/modules/console.rb
Codebreaker_RG2016-0.2.3 lib/codebreaker/modules/console.rb
Codebreaker_RG2016-0.2.2 lib/codebreaker/modules/console.rb
Codebreaker_RG2016-0.2.1 lib/codebreaker/modules/console.rb