#The Commands are going North and South in the Y - variable and East and West in the X - variable and X - to exit the game
x = 0
y = 0
print("Welcome to sloth quest!")
print("________________________________________")
print()
print("You're currently at position (0, 0) in the world.")
print("Available commands:
N - go north, S - go south, E - go east, W - go west, X - exit game)
command = input("Enter a command: ")
if command == ("N"):
y = y 1
elif command == ("E"):
x = x 1
elif command == ("S"):
y = y -1
elif command == ("W"):
x = x -1
#I want to make a loop so that these commands can be input together so that the goal or hazard is reached.
我可以得到幫助嗎?該游戲類似于 Zork 已經列出了命令和我想要做的事情,我認為唯一剩下的就是試圖適應范圍為 [-5, 5] 的回圈。
uj5u.com熱心網友回復:
# The Commands are going North and South in the Y - variable and East and West in the X - variable and X - to exit the game
x = 0
y = 0
print("Welcome to sloth quest!")
print("________________________________________")
print()
print("You're currently at position (0, 0) in the world.")
print(
"Available commands: N - go north, S - go south, E - go east, W - go west, X - exit game")
while True: # run untill the user enters X
# limit play area to -5 x 5
command = input("Enter a command: ")
command = command.upper() # Ensure user input is upper case
if command == ("N"):
y = y 1
elif command == ("E"):
x = x 1
elif command == ("S"):
y = y - 1
elif command == ("W"):
x = x - 1
elif command == 'X': # Exit the loop
break
if x < -5 or x > 5 or y < -5 or y > 5:
# What should happen?
print("error you have left the play area")
print('Thanks for playing') # Exit the game.
# I want to make a loop so that these commands can be input together so that the goal or hazard is reached.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/439917.html
上一篇:如何創建這種回圈?
下一篇:向量子集的Rlapply回圈性能
