您的变量应该不在while循环中,这样就不会一遍又一遍地得到相同的值,而且您还应该每次都更新食堂饮料变量。
更新代码
def main ():
global executed
executed = 1
if executed == 1: # This will only show the intro once
print("Welcome to Camel!")
print("You have stolen a camel to make your way across the great Mobi desert.")
print("The natives want their camel back and are chasing you down!")
print("Survive your desert trek and out run the natives.")
global done # Add global next to a variable if you're calling it from outside the function
executed = 0
main()
import random
done = False
miles_traveled = int(0)
thirst = int(0)
camel_tiredness = int(0)
native_distance = int(-20)
canteen_drinks = int(3)
while not done:
# Game variables
print("A. Drink from your canteen.")
print("B. Ahead moderate speed.")
print("C. Ahead full speed.")
print("D. Stop for the night.")
print("E. Status check.")
print("Q. Quit.")
user_choice = (input("What is your choice? "))
# Quit the game
if user_choice.upper() == "Q":
done = True
print("Quitting...")
# Status check
elif user_choice.upper() == "E":
print("Miles traveled:", miles_traveled)
print("Drinks in Canteen:", canteen_drinks)
print("The natives are", native_distance, "miles behind you.")
# Stopping for the night
elif user_choice.upper() == "D":
camel_tiredness = int(0)
print("Your camel is happy.")
native_distance += random.randint(7, 14)
print("The natives are", native_distance, "miles behind you.")
#Full speed
elif user_choice.upper() == "C":
thirst += int(1)
camel_tiredness += int(1)
miles_traveled += random.randint(10, 20)
print("You have traveled", miles_traveled, "miles.")
native_distance += random.randint(7, 14)
# Moderate speed
elif user_choice.upper() == "B":
miles_traveled += random.randint(5, 12)
print("You have traveled", miles_traveled,"miles.")
thirst += int(1)
camel_tiredness += int(1)
native_distance += random.randint(7, 14)
# Drinking from canteen
elif user_choice.upper() == "A":
if canteen_drinks >= 1:
print("You have taken a sip from your canteen")
canteen_drinks = canteen_drinks - int(1) # you should update the centeen_drinks
print("You have", canteen_drinks, "sips left in your canteen.")
elif canteen_drinks == 0:
print("You are out of water.")
# The other stuff at the end
if thirst > 4 < 6:
print("You are thirsty.")
if thirst > 6:
print("You have died of thirst!")
done = True
if camel_tiredness > 5 < 8:
print("Your camel is tired.")
if camel_tiredness > 8:
print("Your camel has died.")
if native_distance >= 0:
print("The natives have caught you.")
done = True
if native_distance >= -15:
print("The natives are getting close!")
if miles_traveled >= 200:
print("You have won and got away from the natives!")
done = True
oasis = random.randint(0, 20)
if oasis == 20:
print("You have found an oasis.")
thirst = 0
camel_tiredness = 0