class Codebreaker::Game
Constants
- ATTEMPTS
- HINT
Attributes
attempts[R]
game_start[R]
hint[R]
score[R]
secret_code[R]
Public Class Methods
new(score = 0)
click to toggle source
# File lib/codebreaker/game.rb, line 11 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
Public Instance Methods
check_guess(guess)
click to toggle source
# File lib/codebreaker/game.rb, line 20 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
score_count()
click to toggle source
# File lib/codebreaker/game.rb, line 30 def score_count @score += 250 if win? @score += @hint * 100 + @attempts * 50 end