class Tarzan::Games::Base::Game
Public Class Methods
new(options = {})
click to toggle source
# File lib/tarzan/games/base/game.rb, line 5 def initialize(options = {}) @interface = options[:interface] end
Public Instance Methods
play()
click to toggle source
# 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
Private Instance Methods
prompt_move()
click to toggle source
# File lib/tarzan/games/base/game.rb, line 32 def prompt_move # Subclasses are expected to define how to prompt the user for a move end
random_move()
click to toggle source
# File lib/tarzan/games/base/game.rb, line 36 def random_move # Subclasses are expected to define how to get a random move end
rules()
click to toggle source
# File lib/tarzan/games/base/game.rb, line 28 def rules # Subclasses are expected to define rules end