Class: RpsYsc::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/rps_ysc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#weaponObject

Returns the value of attribute weapon.



28
29
30
# File 'lib/rps_ysc.rb', line 28

def weapon
  @weapon
end

Instance Method Details

#aiObject



54
55
56
57
# File 'lib/rps_ysc.rb', line 54

def ai
    @weapon = [1,2,3].sample
    @weapon
end

#enter(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

#initObject

initialize the weapons



30
31
32
# File 'lib/rps_ysc.rb', line 30

def init
    @weapon = 0
end