class Rpsdz::Player
Attributes
hand[RW]
name[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/player.rb, line 8 def initialize(name) @name = name end
Public Instance Methods
prompt_name()
click to toggle source
# File lib/player.rb, line 12 def prompt_name if self.is_a? Computer self.randomize else puts "#{@name}, Rock, Paper, or Scissors? (r/p/s): " @hand = gets.chomp.downcase end end
showdown(p)
click to toggle source
# File lib/player.rb, line 21 def showdown(p) prompt_name p.prompt_name puts "#{@name}: #{@hand} | #{p.name}: #{p.hand}" case @hand when "r" if p.hand == "r" puts "tie" elsif p.hand == "p" puts "#{p.name} wins" elsif p.hand == "s" puts "#{name} wins" end when "p" if p.hand == "r" puts "#{name} wins" elsif p.hand == "p" puts "tie" elsif p.hand == "s" puts "#{p.name} wins" end when "s" if p.hand == "r" puts "#{p.name} wins" elsif p.hand == "p" puts "#{name} wins" elsif p.hand == "s" puts "tie" end else puts "#{hand} is not a valid choice. Please try again" showdown(p) end end