class CodebreakerCaptainjns::Game
Attributes
att_total[R]
attempts[R]
difficulty[R]
hints[R]
hints_total[R]
name[R]
secret[R]
win[R]
Public Class Methods
new(params)
click to toggle source
# File lib/codebreaker_captainjns/game.rb, line 8 def initialize(params) @name = params['username'] @difficulty = params['difficulty'] @attempts = calc_attempts_and_hints(@difficulty)[0] @hints = calc_attempts_and_hints(@difficulty)[1] @win = false @secret = make_number @unused_hints = @secret.chars end
Public Instance Methods
check(number)
click to toggle source
# File lib/codebreaker_captainjns/game.rb, line 18 def check(number) @attempts -= 1 result = check_numbers(@secret.chars, number.chars) @win = true if result == '++++' result end
use_hint()
click to toggle source
# File lib/codebreaker_captainjns/game.rb, line 25 def use_hint return I18n.t('game.no_hints') unless @hints.positive? @hints -= 1 hint(@unused_hints) end