Sha256: 1248f0fba3c4c9974678b69944840e818279c6973e872f9baa062dc1da3b65f1
Contents?: true
Size: 927 Bytes
Versions: 1
Compression:
Stored size: 927 Bytes
Contents
module Tarzan module Games module Base class Game def initialize(options = {}) @interface = options[:interface] end 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 def rules # Subclasses are expected to define rules end def prompt_move # Subclasses are expected to define how to prompt the user for a move end def random_move # Subclasses are expected to define how to get a random move end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tarzan-0.0.3 | lib/tarzan/games/base/game.rb |