I am trying to get rid of my global variables but I am not sucessful doing so.
In this case I let the user assign coordinates when I run the program. From those coordinates we are starting to sail a boat (within a matrix) meaning that the functions I have that control movement need to have access to these coordinates from the input function. Also the movement functions need to assign new values to the coordinates.
koordx = 0
koordy = 0
distancetraveled = 0
def input ():
global koordx
global koordy
koordx = int(input ("Assign Y coordinate)"))
koordy = int(input("Assign Y coordinate"))
..... etc
This is example of movement, changing the coordinates.
def north ():
global distancetraveled
distancetraveled += 2
global koordy
koordy -= 1
def northeast():
global distancetraveled
distancetraveled += 2
global koordx
koordx += 1
global koordy
koordy -= 1
def movement():
if... . .. :
northeast() etc... #moves northeast
input()
movement()
This is just an example, I have some more functions that need to access these coordinates and their values. How can I in a smooth way get rid of my global variables?
This is just a section of my code which I modified to make it more understandable what I need help with.
Any hints would be greatly appreciated.