class Codebreaker::Entities::Game
Constants
- CODE_RANGE
- COUNT_NUMBERS
- DIFFICULTIES
Attributes
attempts[R]
code[R]
hints[R]
Public Class Methods
new()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 27 def initialize @controller = Controller.new end
Public Instance Methods
attempt_wasted()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 50 def attempt_wasted @attempts -= 1 end
check_win?(answer)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 42 def check_win?(answer) code.join == answer end
hint_take()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 54 def hint_take hints.pop end
hints_not_remain?()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 46 def hints_not_remain? hints.empty? end
init_game(difficulty)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 31 def init_game(difficulty) @difficulty = difficulty @code = generate_code @hints = @code.sample(difficulty[:hints]) @attempts = difficulty[:attempts] end
start(guess)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 38 def start(guess) @controller.secret_code_handler(code.join, guess) end
to_h(name)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 58 def to_h(name) { name: name, difficulty: DIFFICULTIES.key(@difficulty), all_attempts: @difficulty[:attempts], all_hints: @difficulty[:hints], attempts_wasted: @difficulty[:attempts] - @attempts, hints_wasted: @difficulty[:hints] - @hints.length, date: Time.now } end
Private Instance Methods
generate_code()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 72 def generate_code Array.new(COUNT_NUMBERS) do rand CODE_RANGE end end