module MG_tools
Rof = {:sustained => rand(3..9), :rapid => rand(5..9), :cyclic =>
rand(1..200), :cease => 0}
end
class M249
include MG_tools
attr_accessor :ammo
def initialize( ammo )
@ammo = ammo
end
def fire(command)
self.ammo -= Rof[command]
raise ArgumentError.new("Out of Ammo!") if self.ammo < 1
end
end
command = :sustained
gunner = M249.new(200)
loop do
case gunner::ammo
when (200..1000)
command = :cyclic
when (100..199)
command = :rapid
when (6..99)
command = :sustained
when (1..5)
command = :cease
end
puts "#{command.upcase} FIRE"
break if command == :cease
gunner.fire(command)
puts "*MACHINE GUN NOISES*"
puts "SAW: #{gunner::ammo} rounds left!"
end
Created
April 11, 2017 01:54
-
-
Save benkoshy/4a9e705f90468d1ae58036c2c94e77ed to your computer and use it in GitHub Desktop.
Machine gun Kata - original code
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment