forked from n2g7/prison-breakout-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
120 lines (89 loc) · 2.52 KB
/
classes.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import random
# Player class
class Player:
strength = 100
popularity = 10
static_inventory = []
mobile_inventory = []
def __init__(self, name, prison) -> None:
self.name = name
self.prison = prison
def __str__(self) -> str:
return self.name
def get_location(self):
for room in self.prison.rooms.values():
if self in room.occupants:
return room
def move(self, new_room):
if new_room in self.prison.rooms:
self.get_location().occupants.remove(self)
self.prison.rooms[new_room].occupants.append(self)
else:
print("No such room")
def bribe(self):
print("How's 'bout I make you an offer you can't refuse?")
def interact(self):
if len(self.get_location().other_occupants(self)) > 0:
other_inmate = random.choice(self.get_location().other_occupants(self))
print("You: Hey")
print(f"{other_inmate.name}: {random.choice(other_inmate.dialogues)}")
else:
print("I'm alone")
# Inmate class
class Inmate:
def __init__(self, name, prison, strength, friendliness, dialogues) -> None:
self.name = name
self.prison = prison
self.strength = strength
self.friendliness = friendliness
self.dialogues = dialogues
def __str__(self) -> str:
return self.name
# Prison guard class
class Guard:
def __init__(self, number, prison, friendliness) -> None:
self.number = number
self.prison = prison
self.friendliness = friendliness
def __str__(self) -> str:
return self.number
# Prison class
class Prison:
def __init__(self, room_names) -> None:
self.rooms = {name:Room(name, [], []) for name in room_names}
def __str__(self) -> str:
return "Adironacks Correctional Facility"
# Room class
class Room:
def __init__(self, name, assets, occupants) -> None:
self.name = name
self.assets = assets
self.occupants = occupants
def __str__(self) -> str:
return self.name
def other_occupants(self, person):
other_occupants = self.occupants.copy()
other_occupants.remove(person)
return other_occupants
# Controller class
class Controller:
def __init__(self, player) -> None:
self.player = player
def get_input(self):
player_input = input("Input: ").lower().strip().split(" ")
try:
if len(player_input) == 1:
getattr(self, player_input[0])()
elif len(player_input) == 2:
getattr(self, player_input[0])(player_input[1])
except:
print("Error")
def goto(self, location):
self.player.move(location)
def talk(self, person):
if person == "guard":
self.player.bribe()
elif person == "inmate":
self.player.interact()
else:
print("No such person")