좋습니다 메서드에서 메서드를 전달할 때마다 메서드에 전달할 때마다 빨아들입니다. 너희들은 내가 어떻게 지나가는 지에 대해 설명 할 수 있니? 여기 여기 메소드를 호출하면 방법 무기독립 실행 형 메서드는 자체적으로 다른 메서드를 호출하고 있습니다.
def Weapon
puts "Now it's time to select your weapon."
puts "Please choose a weapon that is good throughout the game."
puts "Whenever you are shortage of bullets, please reload it."
puts "Please avoid last minute of reloading of weapon."
puts "Now choose your weapon based on your own preferences."
print "\n"
puts "Type 1"
puts "Gun Name: Bazoka"
puts "Description: A powerful gun that is strong with only 5 bullets."
puts "Rating: ★ ★ ★ ★"
num = gets.chomp.to_i
case num
when 1
puts "Selection of Bazoka is chosen"
puts "Loaded 5 bullets only"
$choosen_gun[num] = $Weapon[:Bazoka]
end
return num
end
내 코드의 내 해시
$choosen_gun = {}
$Weapon = {
:Bazoka => ["Bazoka",5],
:Machine_gun => ["Machine_gun",1000],
:Hand_gun => ["Hand_gun",24,2],
:Double_Hand_gun => ["Double_Hand_gun",24,4],
:Sniper => ["Sniper",12,1],
:Shot_gun => ["Shot_gun",8,2]
}
입니다. 사용자는 자신의 무기를 선택하고이 납입의와는 $ choosen_gun 해시에 추가합니다, 그리고 그것의 반환의 납입 어떤 사용자 유형
여기에 방법에 대한 내 코드
def ZombieRoom(w)
zombie = {
:Construcied => [5],
:Invader => [5],
:Damned => [5],
:Steampunk => [5],
:Stoner => [5],
:Wasted => [5],
:Romero => [5]
}
puts "Welcome to the worst night mare of Zombie Room"
puts "You will be fighting with a random zombie"
while true
puts ".........."
puts "Selecting a random zombie"
puts "Selecting your prefered gun...."
case w
when 1
$choosen_gun[1]
puts "Your selected gun is #{$choosen_gun[1][0]}"
#values = zombie.values
#puts values[rand(values.size)]
#random_zombie = zombie.keys.sample(1)
#puts random_zombie[
random_zombie = zombie.to_a.sample(1).to_h
random_zombie.each do |key,value|
puts "Your random zombie is #{key}"
puts "With a health value of #{value[0]}"
puts "Time to take down that zombie now."
while true
puts "Type Shoot to knock it down or quit."
choice = gets.chomp
if $choosen_gun[1][1] >= 1
health = value[0] -= 1
$choosen_gun[1][1] -= 1
puts "#{key} health now is #{health}"
else
puts "Please reload your gun"
puts "Reloading......"
$choosen_gun[1][1] += 5
end
if health == 0
puts "You have defeated #{key}"
puts "Congrats!!!"
puts "We are happy for you"
puts "Lets begins to collect your prize"
CollectPrize()
else
puts "You did not defeat the #{key} yet"
end
end
end
end
end
end
여기에 내 코드가의 ZombieRoom
입니다 방법 CollectPrize 여기def CollectPrize
puts "Congratulations on defeating"
puts "We would now like to give you some case prizes"
print "\n"
puts "Please choose only 1 prize for yourself"
print "\n"
puts "Type 1"
puts "$50,000"
print "\n"
puts "Type 2"
puts "$25,000"
print "\n"
puts "Type 3"
puts "$55,000"
hoho = gets.chomp.to_f
if hoho == 1
puts "hehe"
end
end
내가 내 메서드를 호출하는 방법을
ZombieRoom(Weapon())
CollectPrize()
이제는 문제는 CollectPrize 메소드가 호출 될 때마다 입력을 입력하여 사례 1을 수집하고 "$ 50,000"을 출력한다는 것입니다. 문제를 끝내는 대신 ZombieRoom으로 돌아가서 "유형 찍기"를 반복하여 계속 두들 기거나 종료합니다. 누군가 atleast 나 에게이 문제를 해결하기 위해 적절한 방법이나 다른 방법을 전달하는 방법을 전달할 수 있습니까?
질문이 명확하지 않습니다. "메소드를 메소드에 전달하는"것은 무엇을 의미합니까? 내가 볼 수 있듯이 메서드를 어디서나 메서드에 전달하지 않으므로 그 이유는 무엇입니까? "내가 그 방법에서 무엇인가를 돌려주고 싶을 때"왜 그렇게해야합니까? "너는 내가 어떻게 지나가는 지 설명 할 수 있니?" 인용하다? 또한 [mcve]를 제공하고 "M"(최소) 부분에 특히주의하십시오. 나는 당신이 당신의 문제를 복제하기 위해 120 줄의 코드가 필요하다는 것을 매우 의아하게 생각한다. 사실, 나는 당신의 문제와는 완전히 무관 한 몇 가지 버그를 발견했지만 꽤 많이 만들었습니다 ... –
... 진단 불가능합니다. –
마지막 문장을 읽으면 이해할 수 있습니다. – Suresh