Class: Tarzan::Games::Base::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/tarzan/games/base/game.rb

Direct Known Subclasses

OddsAndEvens::Game, RockPaperScissors::Game

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Game

Returns a new instance of Game.



5
6
7
# File 'lib/tarzan/games/base/game.rb', line 5

def initialize(options = {})
  @interface = options[:interface]
end

Instance Method Details

#playObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tarzan/games/base/game.rb', line 9

def play
  @interface.say %{Rules: #{rules}}

  move_p1 = prompt_move
  move_p2 = random_move

  @interface.say %{You played #{move_p1} - I played #{move_p2}}

  outcome = case move_p1 <=> move_p2
    when 1  then %{You win!}
    when -1 then %{You lose!}
    when 0  then %{It’s a tie!}
  end

  @interface.say outcome
end