forked from bredeson/PnP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
198 lines (172 loc) · 5.98 KB
/
user.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python3
#================================================
# Define main user charactrer class and methods
#================================================
import random, time
import creatures
import combatResponses
from textFormat import print_s, input_s, printHealthBar, combatStatus
class Prisoner(object):
def __init__(self, name = 'Unknown', hp = 50, hpmax = 50 ,level = 1, difficulty = 'medium', attack = 8, intelligence = 2, location = 'Prison', mana = 3):
self.name = name
if difficulty.upper() == 'easy'.upper():
hp = 80
hpmax = 80
intelligence = 3
elif difficulty.upper() == 'medium'.upper():
hp = 50
hpmax = 50
intelligence = 2
elif difficulty.upper() == 'hard'.upper():
hp = 30
hpmax = 30
intelligence = 1
else:
hp = 50
hpmax = 50
intelligence = 2
difficulty = 'medium'
self._intelligence = intelligence
self._level = level
self._hp = hp
self._hpmax = hpmax
self.difficulty = difficulty
self._attack = attack
self.location = location
self._mana = mana
#Properties to check self variables that should not equal 0 and return hidden attr and pass to unhidden versions
@property
def hpmax(self):
if self._hpmax < 10:
self._hpmax = 10
return self._hpmax
@hpmax.setter
def hpmax(self,value):
self._hpmax = value
@property
def hp(self):
if self._hp < 0:
self._hp = 0
return self._hp
@hp.setter
def hp(self, value):
self._hp = value
if self._hp / self._hpmax > 1:
self._hp = self._hpmax
@property
def intelligence(self):
if self._intelligence < 0:
self._intelligence
return self._intelligence
@intelligence.setter
def intelligence(self, value):
self._intelligence = value
@property
def level(self):
if self._level < 1:
self._level = 1
return self._level
@level.setter
def level(self, value):
self._level = value
@property
def attack(self):
if self._attack < 0:
self._attack = 0
return self._attack
@attack.setter
def attack(self, value):
self._attack = value
@property
def mana(self):
if self._mana < 0:
self.mana = 0
return self._mana
@mana.setter
def mana(self, value):
self._mana = value
# Combat function for creature encounters --- calls combatResponses for sassy comments during battle
def combat(self, monster = None):
while monster.hp > 0:
if self.hp <= 0:
print_s('You have died to a ' + monster.name, color = 'red')
time.sleep(1.5)
break
elif monster.hp > 0:
combat_query=input_s('[a]ttack, [r]isky attack, or [m]agic?\n',self)
if combat_query == 'a':
new_user_attack = random.randint(1,self.attack)
new_mon_attack = random.randint(1,monster.attack)
print_s(combatResponses.combatResponse_player(self.attack, new_user_attack) + ' ' + 'You deal ' + str(new_user_attack) + ' damage to ' + monster.name, color = 'red')
time.sleep(1.5)
monster.hp -= new_user_attack
if monster.hp > 0:
print_s('The ' + monster.name + ' has ' + str(monster.hp) + ' health remaining.')
time.sleep(1.5)
self.hp -= new_mon_attack
print_s(combatResponses.combatResponse_monster(monster.attack, new_mon_attack) + ' ' + monster.name + ' does ' + str(new_mon_attack) + ' damage. Your health is now ' + str(self.hp), color = 'red')
time.sleep(1.5)
else:
print_s('The ' + monster.name + ' is dead.\n')
time.sleep(1.5)
break
if combat_query == 'r':
chance = random.randint(1,20)
min_damage = int(0.5*self.attack)
max_damage = 2*self.attack
new_user_attack = random.randint(min_damage,max_damage)
new_mon_attack = random.randint(1,monster.attack)
if chance > 10:
print_s(combatResponses.combatResponse_player(self.attack, new_user_attack) + ' '+ 'You deal ' + str(new_user_attack) + ' damage to ' + monster.name, color = 'red')
time.sleep(1.5)
monster.hp -= new_user_attack
if monster.hp > 0:
print_s('The ' + monster.name + ' has ' + str(monster.hp) + ' health remaining.')
time.sleep(1.5)
self.hp -= new_mon_attack
print_s(combatResponses.combatResponse_monster(monster.attack, new_mon_attack) + ' ' + monster.name + ' does ' + str(new_mon_attack) + ' damage. Your health is now ' + str(self.hp), color = 'red')
time.sleep(1.5)
else:
print_s('The ' + monster.name + ' is dead.\n')
time.sleep(1.5)
break
else:
print_s(combatResponses.missResponse(), color = 'purple')
time.sleep(1.5)
self.hp -= new_mon_attack
print_s(combatResponses.combatResponse_monster(monster.attack, new_mon_attack) + ' ' + monster.name + ' does ' + str(new_mon_attack) + ' damage. Your health is now ' + str(self.hp), color = 'red')
time.sleep(1.5)
if combat_query == 'm':
if self.mana > 0:
new_user_attack = self.attack
new_mon_attack = random.randint(1,monster.attack)
print_s(combatResponses.magicResponse() + str(new_user_attack) + ' damage.', color = 'red')
time.sleep(1.5)
monster.hp -= new_user_attack
self.mana -= 1
print_s('You have ' + str(self.mana) + ' mana left.')
time.sleep(1.5)
if monster.hp > 0:
print_s('The ' + monster.name + ' has ' + str(monster.hp) + ' health remaining.')
time.sleep(1.5)
self.hp -=new_mon_attack
print_s(combatResponses.combatResponse_monster(monster.attack, new_mon_attack) + ' ' + monster.name + ' does ' + str(new_mon_attack) + ' damage. Your health is now ' + str(self.hp), color = 'red')
time.sleep(1.5)
else:
print_s('The ' + monster.name + ' is dead.\n')
time.sleep(1.5)
break
else:
print_s('You have no mana left!', color = 'blue')
time.sleep(1.5)
else:
break
combatStatus(self)
# Methods to set self variables
def setHP(self, new_hp = None):
self.hp = new_hp
def setescapeStatus(self, escapeStatus = False):
self.escapeStatus = escapeStatus
def setAttack(self, attack_inc = 0):
self.attack += attack_inc
print('Your attack damage has increased to ',self.attack,'.\n', sep = '')