Witam,
jestem początkującym programistą i jestem w trakcie pisania swojej pierwszej gry tekstowej.
Napotkałem problem z pętlą a mianowicie z poniższym kodem.
while gameLength > 0:
gameAnswer = input("Do you want to move forward? \n")
if gameAnswer == "yes":
print("Great, lets see what is inside")
drawnEvent = random.choices(eventList, eventProbability)[0]
if drawnEvent == Event.Chest:
drawnChest = random.choices(chestList, chestProbability)[0]
goldAcquire = find_aprox_value(colorValue[drawnChest])
print("You have find ", drawnChest.value, "inside was", goldAcquire, "gold")
Gold = Gold + goldAcquire
gameLength = gameLength - 1
elif drawnEvent == Event.Monster:
drawnMonster = random.choices(MonsterList, MonsterProbability)[0]
print("Oh no, you have find", drawnMonster.value, "which has", monsterLife[drawnMonster],
"life .If you will defeat him, you will find great treasure.")
eventAnswer = input(" What is your choice?(fight, run)")
if eventAnswer == "fight":
while monsterLife[drawnMonster] > 0:
weapon_hit(0)
if monsterLife[drawnMonster] > 0:
monster_hit()
if playerLife <= 0:
print("You died, your body will lay in chambers forever")
sys.exit(0)
drawnPremiumChest = random.choices(PremiumChestList, PremiumChestProbability)[0]
goldAcquire = find_aprox_value(colorValue[drawnPremiumChest])
print("Congratulations, you have defeat a monster, and you found", drawnPremiumChest.value,
", inside was", goldAcquire, " gold")
Gold = Gold + goldAcquire
gameLength = gameLength - 1
elif eventAnswer == "run":
gameLength = gameLength - 1
print("you have successfully run")
else:
print("Only options is run or fight")
w chwili obecnej w momencie spotkania potwora i wyboru innej opcji niż run lub fight, program cofa mnie na sam początek pętli z komunikatem "do you want to move forward".
Chciałbym, żeby po wyborze złej komendy nie dochodziło znowu do losowania zdarzenia, tylko, żeby program znowu zapytał mnie czy chce walczyć czy uciec.
Będę bardzo wdzięczny za pomoc.
Pozdrawiam