-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosition.py
32 lines (26 loc) · 844 Bytes
/
Position.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pygame
from Direction import Direction
# Position class, it's a set of positions (x,y)
class Position:
# Position constructor
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "X-" + str(self.x) + " | Y:" + str(self.y)
# get the next position based on direction
def get_next_position(self, direction):
x = self.x
y = self.y
if direction == Direction.LEFT:
x -= 1
if direction == Direction.RIGHT:
x += 1
if direction == Direction.UP:
y -= 1
if direction == Direction.DOWN:
y += 1
return Position(x, y)
def get_pos_from_move(self, move):
direction = Direction.get_direction_from_pos_move(self, move)
return self.get_next_position(direction)