ãð°åå¿è ãå ¥ãåæ§é ã®loopããæãåºããªãïŒæ¡ä»¶åå²ãäžæãåºæ¥ãªã
解決ãããããšïŒè©²åœç®æã¯äžéšloop以éã®ã³ãŒãã§ããïŒ
çŸåšRubyã§ãã£ã¡åããŠãã€ã¢ããªãå®è£
ããŠããŸãã
ãããããã¡ãœããã«true/falseãè¿ãããã«ãïŒfïŒïŒããã£ã¡åããŠãã€ã¡ãœããã«ãtrue/falseãè¿ãããã«ããŸãããïŒfïŒïŒ
ãã®åŸãã®çåœå€ãçšããŠãããããã§åæãã€ããŸã§ã«ãŒãâãã£ã¡åããŠãã€ã§åãæ¹åãåããŸã§ã«ãŒããšããã³ãŒããæžããŸãããããåæãã€ããŸãããã®åŸã«ããããããããŸãå§ãŸã£ãŠããŸããŸãã
isBreakãæžããŠããäœçœ®ãééã£ãŠããã®ã§ããããïŒ
ãããŠæ¬æ¥ã¯æåŸã®æãããããããã«åã£ãå Žåããè² ããå Žåãã§
åããã¹ããªã®ã§ããããããåºæ¥ãŠããªãç¶æ³ã§ãã
ãããããã¡ãœããã®æ»ãå€ããtrueããfalseãã§ã¯ãªããïŒããïŒãã«æžãæããloopã®äžã®ifæã®äžã«ããã«ifæãæžãçµã¿èŸŒãããšããŠã¿ãŸããã
ãšã©ãŒã§å®è¡ãããã»ã»ã»ãç
®è©°ãŸã£ãŠããŸããŸããã
require "csv"
puts"------------------------------"
puts"ãã£ã¡åããŠãã€ã²ãŒã ãå§ããŸãã"
def janken
puts "ãããããã»ã»ã»"
puts "0(ã°ãŒ)1(ãã§ã)2(ããŒ)3(æŠããªã)"
select_number = gets.to_i
if !(select_number == 0 || select_number == 1 || select_number ==2)
select_number = 3
end
random_number = rand(3)
jankens = ["ã°ãŒ","ãã§ã","ããŒ","æŠããªã"]
puts "ããªãïŒ#{jankens[select_number]} çžæïŒ#{jankens[random_number]}"
puts"------------------------------"
if select_number ==3 || random_number == 3
puts"ããããããæŸæ£ãããŸãããã²ãŒã ãçµäºããŸãã"
exit
end
number = select_number - random_number
if number == 0
puts "ãããã§ããããäžåºŠããããããããŸãã"
false
elsif number == 1 || number == -2
puts"ãããããã«è² ããŸããããã£ã¡ãããŠã»ã»ã»"
true
elsif number == -1 || number == 2
puts "ãããããã«åã¡ãŸããããã£ã¡ãããŠã»ã»ã»"
true
end
end
def acchimuite_hoi
puts "0(äž)1(äž)2(å·Š)3(å³)"
select_number2 = gets.to_i
random_number2 =rand(3)
directions = ["äž","äž","å·Š","å³"]
puts"ãã€ïŒ"
puts "ããªãïŒ#{directions[select_number2]} çžæïŒ#{directions[random_number2]}"
puts"------------------------------"
if select_number2 == random_number2
true
else
false
end
end
loop do
f1 = janken # ãããããããç¶ãã
if f1 # ããããããããã§åæãã€ããã
loop do
f2 = acchimuite_hoi # ãã£ã¡åããŠãã€ããç¶ãã
if f2 # åãæ¹åãåããã
puts"åæãã€ããŸãã"
isBreak = true
break
else
next # ãããããããããçŽã
end #IFæçµäº
break if isBreak
end # ã«ãŒãçµäº
else # ãããããã§åæãã€ããªãã£ãã
next # ãããããããããçŽã
end # IFæçµäº
end # ã«ãŒãçµäº
if f1
puts"ããªãã®åã¡ã§ã"
else
puts"ããªãã®è² ãã§ã"
end