class MegaRps::Game
handle game logic/flow
Player
Make move
Human
< Player
Collect input from command line
Computer
< Player
Generate move randomly
Public Class Methods
new()
click to toggle source
# File lib/mega_rps.rb, line 18 def initialize @player = Human.new @computer = Computer.new end
Public Instance Methods
play_again?()
click to toggle source
# File lib/mega_rps.rb, line 67 def play_again? puts "Would you like to play again? Y/N" if gets.chomp[0].downcase == 'y' true else false end end
play_game()
click to toggle source
# File lib/mega_rps.rb, line 26 def play_game print_instructions while play_again? @player.move @computer.move print_result play_again? end end
print_instructions()
click to toggle source
# File lib/mega_rps.rb, line 40 def print_instructions p "Let's play MEGA Rock, Paper, Scissors!" p "Enter (r)ock, (p)aper, or (s)cissors to make your move >>" end
print_result()
click to toggle source
# File lib/mega_rps.rb, line 49 def print_result if @player.move == @computer.move puts "Draw" elsif @player.move == 's' && @computer.move == 'r' || @player.move == 'p' && @computer.move == 's' || @player.move == 'r' && @computer.move == 'p' puts "Computer Wins" else puts "You Win" end end