我正在尝试用Python模拟一个简单的游戏。在这个游戏中,玩家会掷一个骰子,然后根据骰子(从1到6的数字)从当前位置移动到终点线(位于位置100)。
我正试图想出一个可以完成以下任务的函数:添加当前位置和骰子的结果。但是,如果这个函数给出一个大于100的数字,那么这个函数将忽略它并再次抛出骰子,因为100之后没有位置。
下面你可以找到我想出的“伪代码”(一半是真正的代码,一半是我的想法/评论):
import random
def movement(current_position, distance):
current_position = 0 #a counter should be added here I guess to increment the position
distance = random.randint(1,6)
move = current_position + distance
if move > 100; do:
#function telling python to ignore it and throw the dice again
elif move = 100; do:
print("You reached position 100")
else:
return move
你能帮我弄明白怎么做吗?