我是计算机科学学位的大一新生,我被派去完成这个骆驼游戏。在移动后检查状态时,我似乎找不到更新变量的方法。他们总是打印出旅行的英里数是0,而当地人落后了-20英里。感谢您的帮助!
这是我的密码。
# The comments are from my friend who helped me fix the while loop from repeating over and over
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()
done = False
while not done:
# Game variables
miles_traveled = int(0)
thirst = int(0)
camel_tiredness = int(0)
native_distance = int(-20)
canteen_drinks = int(3)
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.")
import random
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)
import random
miles_traveled += random.randint(10, 20)
print("You have traveled", miles_traveled, "miles.")
import random
native_distance += random.randint(7, 14)
# Moderate speed
elif user_choice.upper() == "B":
import random
miles_traveled += random.randint(5, 12)
print("You have traveled", miles_traveled,"miles.")
thirst += int(1)
camel_tiredness += int(1)
import random
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")
print("You have", canteen_drinks - int(1), "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
import random
oasis = random.randint(0, 20)
if oasis == 20:
print("You have found an oasis.")
thirst = 0
camel_tiredness = 0