41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
class Trac:
|
|
def __init__(self, rotation, position):
|
|
self.__position = position
|
|
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):
|
|
self.__position[0] = position[0]
|
|
self.__position[1] = position[1]
|
|
|
|
def get_position(self):
|
|
return self.__position
|
|
|
|
def get_rotation(self):
|
|
return self.__rotation
|
|
|
|
def move(self):
|
|
x = self.__position[0]
|
|
y = self.__position[1]
|
|
if self.__rotation == 'N':
|
|
self.__position = (x - 1, y)
|
|
elif self.__rotation == 'S':
|
|
self.__position = (x + 1, y)
|
|
elif self.__rotation == 'W':
|
|
self.__position = (x, y - 1)
|
|
else:
|
|
self.__position = (x, y + 1)
|
|
|