Sha256: 954692a6a504d5a52cbdd0bda865c43270948524a937ec3a3974a10a3c85d776
Contents?: true
Size: 781 Bytes
Versions: 3
Compression:
Stored size: 781 Bytes
Contents
require_relative 'modules/marker' module Codebreaker class Game include Marker ATTEMPTS = 6 HINT = 1 attr_reader :secret_code, :hint, :attempts, :score, :game_start def initialize(score = 0) @secret_code = Array.new(4) { rand(1..6) }.join @player_code = '' @hint = HINT @attempts = ATTEMPTS @score = score @game_start = true end def check_guess(guess) @player_code = guess if @player_code == 'hint' && @hint.nonzero? @attempts += 1 @hint -= 1 puts "Hint: Secret code contains: #{@secret_code[rand(0..3)]}" end check_win end def score_count @score += 250 if win? @score += @hint * 100 + @attempts * 50 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
Codebreaker_RG2016-0.2.3 | lib/codebreaker/game.rb |
Codebreaker_RG2016-0.2.2 | lib/codebreaker/game.rb |
Codebreaker_RG2016-0.2.1 | lib/codebreaker/game.rb |