0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rubyでリスキーダイスを作ってみた

Posted at

rubyの練習でハンターハンターに登場するリスキーダイスを作ってみた。
1から20の数字があり20が大凶です。

def risky_daice
  array = []
  puts '何回振ろうかな'
  stop = gets.to_i
  puts 'ダイスを振るよ'
  while true
    deme = rand(1..20)
    num = array.push deme
    if deme == 20
      puts deme
      puts 'あーあ出ちゃった'
      p "#{num.count}回目で大凶がでた"
      break
    elsif num.count == stop
      puts deme
      puts 'そこでやめ'
      p "#{num.count}回振れたよ。また挑戦してね"
      break
    else
      puts deme
    end
  end
end
risky_daice
-> % ruby risky_daice.rb

何回振ろうかな
20
ダイスを振るよ
16
12
4
1
12
8
18
19
15
2
16
5
3
5
5
3
20
あーあ出ちゃった
"17回目で大凶がでた"

本番の前に振るといいことあるかも?

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?