Repository navigation
Expand file tree
/
Copy pathtype.py
More file actions
executable file
·83 lines (66 loc) · 1.91 KB
/
Copy pathtype.py
File metadata and controls
executable file
·83 lines (66 loc) · 1.91 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from dataclasses import dataclass
from enum import Enum
class RoomType(Enum):
HALL = "Hallway"
KITCHEN = "Kitchen"
GARDEN = "Garden"
LIBRARY = "Library"
OFFICE = "Office"
LABORATORY = "Laboratory"
class NPC(Enum):
Monster = "Monster"
class Item(Enum):
Potion = "Potion"
Key = "Key"
Chopsticks = "Chopsticks"
BookOfLife = "BookOfLife"
BeamOMat = "Beam-O-Mat"
@dataclass
class Room:
room_type: RoomType
x: int
y: int
content: Item|NPC|None = None
@property
def name(self):
return self.room_type.value
@dataclass
class Player:
x: int
y: int
inventory: list[str]
def get_current_room(self, rooms: list[list[Room]]) -> Room:
return rooms[self.x][self.y]
def has_potions(self) -> bool:
return Item.Potion.value in self.inventory
def has_key(self) -> bool:
return Item.Key.value in self.inventory
def has_book(self) -> bool:
return Item.BookOfLife.value in self.inventory
def has_beamomat(self) -> bool:
return Item.BeamOMat.value in self.inventory
def move_up(self, rooms: list[list[Room]]):
if self.x > 0:
self.x -= 1
else:
print("You hit a wall! You can't go further north.")
def move_down(self, rooms: list[list[Room]]):
if self.x < len(rooms) - 1:
self.x += 1
else:
print("You hit a wall! You can't go further south.")
def move_left(self, rooms: list[list[Room]]):
if self.y > 0:
self.y -= 1
else:
print("You hit a wall! You can't go further west.")
def move_right(self, rooms: list[list[Room]]):
if self.y < len(rooms[0]) - 1:
self.y += 1
else:
print("You hit a wall! You can't go further east.")
@dataclass()
class GameConfig:
rows: int = 3
rooms_per_row: int = 3
monster_count: int = 2