lib/codeguessing/console.rb in codeguessing-0.4.4 vs lib/codeguessing/console.rb in codeguessing-0.4.5
- old
+ new
@@ -1,39 +1,40 @@
module Codeguessing
class Console
attr_reader :game, :scores, :path
+ RULES = [
+ '-----------------Rules!----------------------',
+ "You need guess secret code. This four-digit number with symbols from 1 to 6",
+ "You have #{Game::MAX_ATTEMPTS} attempt(s) and #{Game::MAX_HINT} hint(s)",
+ "If you want get hint write 'hint'",
+ '---------------------------------------------'
+ ]
+
def initialize(opt = {})
@path = File.join(File.dirname(__FILE__), 'scores.yml')
@scores = load(@path)
@game = Game.new(opt)
end
- def go(know = true)
- rules if know
+ def go(knowed = false)
+ rules unless knowed
puts "Attempt(s): #{@game.attempts} | Hint(s): #{@game.hint_count}"
- case @game.state
- when 'true'
- win
- when 'false'
- loose
- else
- gaming
+ case @game.win?
+ when true
+ win
+ when false
+ loose
+ else
+ gaming
end
end
def rules
puts "Do you know rules? (Y/N)"
- rules = [
- '-----------------Rules!----------------------',
- "You need guess secret code. This four-digit number with symbols from 1 to 6",
- "You have #{@game.attempts} attempt(s) and #{@game.hint_count} hint(s)",
- "If you want get hint write 'hint'",
- '---------------------------------------------'
- ]
unless confirm?
- puts rules.join("\n")
+ puts RULES.join("\n")
end
end
def gaming
action = gets.chomp
@@ -57,11 +58,11 @@
def load(path)
YAML.load(File.open(path)) if File.exist?(path)
end
def save!(name = 'Anonim')
- if @game.state != 'true'
+ unless @game.win?
return puts 'You cant save game'
end
name.chomp!
@scores << @game.cur_score(name)
File.new(@path, 'w') unless File.exist?(@path)
@@ -94,10 +95,10 @@
def again?
puts 'Do you want start again? (Y/N)'
if confirm?
@game = Game.new
- return go(false)
+ return go(true)
else
puts '-----------Scores----------'
p @scores
puts '---------------------------'
end