現在独学でRuby学習中のものです。
下記コードを作りました。
分からないことが多々あったので、教えていただきたく思います。
ruby
1#rotation 通常Modeの回転数 2#firstHit 初当たりの回数 3#hit16R 16R当たり回数 4#hit6R 6R当たり回数 5#wonPachinkoBall 出玉数 6 7=begin 8 通常モードの処理。 9 1/319で初当たり当選。 10 出玉が1280発貰える。 11 その後確立変動への抽選処理へ移行する。 12=end 13 14def normalMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 15 loop do 16 17 result = rand(319)+1 18 rotation += 1 19 20 if result > 318 then 21 puts "大当たり" 22 firstHit += 1 23 wonPachinkoBall += 1280 24 vChallenge(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 25 else 26 puts "はずれ" 27 end 28 end 29end 30 31=begin 32 確立変動への抽選処理 33 5割で確立変動Modeへ突入する。 34 確立変動Modeの抽選に漏れた場合は、通常モードの処理へ移行する。 35 確立変動Modeの抽選に当選した場合は、出玉を520増やし、確立変動モードへ移行する。 36=end 37 38def vChallenge(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 39 result = rand(10)+1 40 if result > 5 then 41 puts "確変突入" 42 wonPachinkoBall += 520 43 vMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 44 else 45 puts "リベンジモード突入" 46 normalMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 47 end 48end 49 50=begin 51 確立変動モードの処理 52 120回転以内に1/75の抽選に当選すれば、出玉を(1800(70%)/600(30%))で増やし、回転数をリセットする。 53 120回転以内に1/75の抽選に当選しなければゲーム終了。 54 清算処理へ移行する。 55=end 56 57def vMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 58 i = 0 59 while i < 120 do 60 i = i+1 61 result = rand(75)+1 62 if result > 74 then 63 puts "Vistory" 64 i = 1 65 win = rand(100)+1 66 if win > 31 67 wonPachinkoBall += 1800 68 hit16R += 1 69 else 70 wonPachinkoBall += 600 71 hit6R += 1 72 end 73 else 74 puts "はずれ" 75 end 76 end 77 puts "確変終了" 78 clear(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 79end 80 81 82=begin 83 清算処理 84 通常回転数、初当たり回数、16R取得回数、6R取得回数、出玉、投資を出力する。 85 プログラムを終了する。 86=end 87def clear(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 88 investment = rotation / 3 89 if investment < 5 then 90 investment = 5 91 end 92 93 print "通常回転数は",rotation,"回\n" 94 print "初当たり回数は",firstHit,"回\n" 95 print "16R取得回数は",hit16R,"回\n" 96 print "6R取得回数は",hit6R,"回\n" 97 print "出玉は",wonPachinkoBall,"発で、換金すると",wonPachinkoBall*4,"円です。" 98 print "投資は",investment,"00円です。" 99 exit(0) 100end 101 102normalMode(0,0,0,0,0)
分からなかったこと。
・Rubyでのmodelの作り方がわからず、引数が多い。
⇒model.hoge = ~ ってやりたい。
⇒hogemethod(model)ってやりたい。
・投資の金額を500区切りの切り上げにしたいがやり方がわからない。
⇒例えば投資金額が1400だったら1500にしたい。
⇒1600だったら2000にしたい。
⇒四捨五入ではないし、切り上げでもない。
⇒しいて言うなら切り上げに区切りの制御を入れた感じ。
ちなみに処理的には動くはずなので、
動かしてみて、いくら勝てたか教えてくれ。(笑
【追記/編集しました。】
ruby
1#rotation 総回転数 2#firstHit 初当たりの回数 3#hit16R 16R当たり回数 4#hit6R 6R当たり回数 5#wonPachinkoBall 出玉数 6 7=begin 8 通常モードの処理。 9 1/319で初当たり当選。 10 出玉が1280発貰える。 11 その後確立変動への抽選処理へ移行する。 12=end 13 14def normalMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 15 loop do 16 17 result = rand(99)+1 18 rotation += 1 19 20 if result > 98 then 21 puts "大当たり" 22 firstHit += 1 23 wonPachinkoBall += 320 24 vChallenge(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 25 else 26 puts "はずれ" 27 end 28 end 29end 30 31=begin 32 確立変動への抽選処理 33 5割で確立変動Modeへ突入する。 34 確立変動Modeの抽選に漏れた場合は、通常モードの処理へ移行する。 35 確立変動Modeの抽選に当選した場合は、出玉を520増やし、確立変動モードへ移行する。 36=end 37 38def vChallenge(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 39 result = rand(10)+1 40 if result > 5 then 41 puts "確変突入" 42 wonPachinkoBall += 260 43 vMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 44 else 45 puts "リベンジモード突入" 46 normalMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 47 end 48end 49 50=begin 51 確立変動モードの処理 52 100回転以内に1/80の抽選に当選すれば、出玉を(1200(50%)/400(50%))で増やし、回転数をリセットする。 53 100回転以内に1/80の抽選に当選しなければゲーム終了。 54 清算処理へ移行する。 55=end 56 57def vMode(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 58 i = 0 59 while i < 100 do 60 i = i+1 61 result = rand(80)+1 62 rotation += 1 63 if result > 79 then 64 puts "Vistory" 65 i = 1 66 win = rand(100)+1 67 if win > 49 68 wonPachinkoBall += 1200 69 hit16R += 1 70 else 71 wonPachinkoBall += 400 72 hit6R += 1 73 end 74 else 75 puts "はずれ" 76 end 77 end 78 puts "確変終了" 79 clear(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 80end 81 82 83=begin 84 清算処理 85 総回転数、初当たり回数、16R取得回数、6R取得回数、出玉、投資を出力する。 86 プログラムを終了する。 87=end 88def clear(rotation,firstHit,hit16R,hit6R,wonPachinkoBall) 89 investment = rotation / 3 90 if investment < 5 then 91 investment = 5 92 end 93 investment /= 5.0 94 investment = (investment).ceil 95 investment *= 5 96 kankin = (wonPachinkoBall * 4)/500.0 97 kankin = kankin.floor 98 kankin *= 500 99 100 print "通常回転数は",rotation,"回\n" 101 print "初当たり回数は",firstHit,"回\n" 102 print "16R取得回数は",hit16R,"回\n" 103 print "6R取得回数は",hit6R,"回\n" 104 print "出玉は",wonPachinkoBall,"発で、換金すると",kankin,"円です。" 105 print "投資は",investment,"00円です。" 106 exit(0) 107end 108 109normalMode(0,0,0,0,0)
クラス適応はまだですが。
とりあえず500単位に出来ました。
回答3件
あなたの回答
tips
プレビュー