I tried to make a risky dice that appears in Hunter Hunter by practicing ruby. There are numbers from 1 to 20, and 20 is a villain.
def risky_daice
array = []
puts 'How many times should i shake'
stop = gets.to_i
puts 'I'll roll the dice'
while true
deme = rand(1..20)
num = array.push deme
if deme == 20
puts deme
puts 'Ah, it came out'
p "#{num.count}The villain came out at the second time"
break
elsif num.count == stop
puts deme
puts 'Stop there'
p "#{num.count}It shook. Please challenge again"
break
else
puts deme
end
end
end
risky_daice
-> % ruby risky_daice.rb
How many times should i shake
20
I'll roll the dice
16
12
4
1
12
8
18
19
15
2
16
5
3
5
5
3
20
Ah, it came out
"The 17th time was a terrible disaster"
Is it good to shake it before the performance?
Recommended Posts