lib/codebreaker/game.rb in codebreaker-0.1.3.1 vs lib/codebreaker/game.rb in codebreaker-0.1.3.2
- old
+ new
@@ -1,20 +1,22 @@
module Codebreaker
class Game
HINTS_COUNT = 2
- DEF_MAX_SCORE = 500
+ MAX_SCORE = 500
+ MAX_ROUNDS = 500
CODE_LENGTH = 4
ROUND_PENALTY = 10
HINT_PENALTY = 50
- attr_reader :round_number, :gues_results
+ attr_reader :round_number, :gues_results, :game_status
def initialize
@secret_code = ""
@round_number = 0
@hints_used = 0
@gues_results = {}
+ @game_status = 'play'
end
def start
CODE_LENGTH.times {
@secret_code += (Random.rand(6) + 1).to_s
@@ -44,19 +46,21 @@
end
end
result = pluses + minuses
@gues_results[gues.to_s] = result
@round_number += 1
+ @game_status = 'win' if result == '++++'
+ @game_status = 'loose' if @round_number >= MAX_ROUNDS
result
end
def hint
raise 'Called hint to many times' unless @hints_used < HINTS_COUNT
@hints_used += 1
@secret_code[Random.rand(4)]
end
def score
- DEF_MAX_SCORE - @hints_used*HINT_PENALTY - @round_number*ROUND_PENALTY
+ MAX_SCORE - @hints_used*HINT_PENALTY - @round_number*ROUND_PENALTY
end
end
end
\ No newline at end of file