SZI_PROJEKT_GR1_TRAKTOR/Trac.py

41 lines
1.0 KiB
Python
Raw Permalink Normal View History

2019-05-06 12:51:41 +02:00
class Trac:
def __init__(self, rotation, position):
2019-05-07 15:37:27 +02:00
self.__position = position
2019-05-06 12:51:41 +02:00
self.__rotation = rotation
def get_symbol(self):
if self.__rotation == 'S':
return 'v'
elif self.__rotation == 'N':
return '^'
elif self.__rotation == 'E':
return '>'
else:
return '<'
def set_rotation(self, rotation):
self.__rotation = rotation
def set_position(self, position):
2019-05-07 15:37:27 +02:00
self.__position[0] = position[0]
self.__position[1] = position[1]
2019-05-06 12:51:41 +02:00
def get_position(self):
return self.__position
def get_rotation(self):
return self.__rotation
def move(self):
2019-05-07 15:37:27 +02:00
x = self.__position[0]
y = self.__position[1]
2019-05-06 12:51:41 +02:00
if self.__rotation == 'N':
2019-05-07 15:37:27 +02:00
self.__position = (x - 1, y)
2019-05-06 12:51:41 +02:00
elif self.__rotation == 'S':
2019-05-07 15:37:27 +02:00
self.__position = (x + 1, y)
2019-05-06 12:51:41 +02:00
elif self.__rotation == 'W':
2019-05-07 15:37:27 +02:00
self.__position = (x, y - 1)
2019-05-06 12:51:41 +02:00
else:
2019-05-07 15:37:27 +02:00
self.__position = (x, y + 1)
2019-05-06 12:51:41 +02:00