lib/codebreaker/game.rb in Codebreaker_RG2016-0.1.6 vs lib/codebreaker/game.rb in Codebreaker_RG2016-0.2.0
- old
+ new
@@ -1,35 +1,36 @@
+require_relative 'modules/marker'
+
module Codebreaker
class Game
- include Engine
- include Score
+ include Marker
ATTEMPTS = 7
HINT = 1
CODE_SIZE = 4
RANGE = 1..6
- attr_accessor :secret_code, :player, :hint, :attempts
- def initialize(player = Player.new)
+ attr_accessor :secret_code, :player_code, :hint, :attempts, :score
+ def initialize(score = 0)
@secret_code = Array.new(CODE_SIZE) { rand(RANGE) }.join
- @player = player
- @hint = HINT
- @attempts = ATTEMPTS
-
- start
+ @player_code = ''
+ @hint = HINT
+ @attempts = ATTEMPTS
+ @score = score
end
- def start
- puts "You have #{@attempts} attempts and #{@hint} hint."
- check_guess
- score
- new_game? ? start : save_score?
+ def check_guess(guess)
+ @player_code = guess
+ if @player_code == 'hint' && @hint.nonzero?
+ puts 'Hint: Secret code contains: ' + @secret_code[rand(0..3)]
+ @hint -= 1
+ @attempts += 1
+ end
+ check_win
end
- private
-
- def new_game?
- puts 'Do you want to start new game?(y/n)'
- Game.new(@player) if @player.agree?
+ def score_count
+ @score += 250 if win?
+ @score += @hint * 100 + @attempts * 50
end
end
end