I am trying to simulate a simple game in python. In this game, the player would throw a dice and would move from their current position towards the end line (located in position 100), depending on the dice (which is numbered from 1 to 6).
I'm trying to come up with a function that would do the following: add the current position and the result of the dice. However, if this function gives a number higher than 100, the function would ignore it and throw the dice again, since there's no positions after 100.
Below you can find the 'pseudo-code' I've come up with (half real code, half my ideas/comments):
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
Could you help me figure out how to do this?
1or just add it on?