-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
31 lines (26 loc) · 970 Bytes
/
player.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
#! /usr/bin/env python3
# coding: utf-8
"""This module contains the 'Player' class."""
class Player:
"""This class is used to represent the player in the labyrinth."""
def __init__(self, x_pos, y_pos):
"""This special method is the class constructor."""
self.is_alive = True
self.wins = False
self.x_pos = x_pos # type is int
self.y_pos = y_pos # type is int
self.authorized_movements = {"up": False, "down": False,
"left": False, "right": False}
def move(self, direction):
"""This method moves the player one step into 'direction',
if authorized."""
if direction == "up":
self.y_pos -= 1
elif direction == "down":
self.y_pos += 1
elif direction == "left":
self.x_pos -= 1
elif direction == "right":
self.x_pos += 1
else:
raise ValueError(direction)