class RpsYsc::Input
Attributes
weapon[RW]
Public Instance Methods
ai()
click to toggle source
# File lib/rps_ysc.rb, line 54 def ai @weapon = [1,2,3].sample @weapon end
enter(name)
click to toggle source
# File lib/rps_ysc.rb, line 34 def enter(name) puts "#{name}, choose the weapon you want" puts "scissor:1, paper:2, rock:3, use numbers to enter" puts "illegal enter will be asked to do it again, you can choose to quit by pressing q" @weapon = gets.chomp abort "you choose to quit" if @weapon == "q" @weapon = @weapon.to_i while ![1,2,3].include?(@weapon) do puts "you input is illegal, do it again" @weapon = gets.chomp.to_i end @weapon end
init()
click to toggle source
initialize the weapons
# File lib/rps_ysc.rb, line 30 def init @weapon = 0 end