lib/mathy/game.rb in mathy-0.0.1 vs lib/mathy/game.rb in mathy-0.0.2
- old
+ new
@@ -1,26 +1,27 @@
module Mathy
class Game
- def initialize(console, score = 0)
- @name = console.greet
+ def initialize(player, score = 0)
+ @player = player
@score = score
end
- def play(games_to_play = 2, operation, difficulty)
- games_to_play.times do
- @score += 1 if operation.play_turn(difficulty.next_operands)
- end
-
- display_results(@name, @score, games_to_play)
+ def play(console)
+ turns_played = play_turns(console)
+ console.display_results(@player, @score, turns_played)
end
private
- def display_results(name, score, games_to_play)
- puts ""
- puts "+++++++++++++++++++++++++++++++++++"
- puts "You got #{score}/#{games_to_play}."
- puts "Good bye #{name}"
- puts "+++++++++++++++++++++++++++++++++++"
+ def play_turns(console)
+ turns_to_play = console.how_many_turns?
+ turns_to_play.times do
+ @score += 1 if operation(console).play_turn
+ end
+ turns_to_play
+ end
+
+ def operation(console)
+ @operation ||= console.difficulty?.choose_operation(console)
end
end
end