-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
32 lines (26 loc) · 999 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
32
class Player:
def __init__(self, name="Engineer", level=1, hp=100, mp=50, inventory=None, xp=0):
self.name = name
self.level = level
self.hp = hp
self.mp = mp
self.xp = xp
self.inventory = inventory or ["Rusty Sword", "Healing Potion"]
def take_damage(self, amount):
self.hp = max(0, self.hp - amount)
def restore_hp(self, amount):
# assuming a maximum HP of 100
self.hp = min(100, self.hp + amount)
def use_mp(self, amount):
self.mp = max(0, self.mp - amount)
def restore_mp(self, amount):
# assuming a maximum MP of 50
self.mp = min(50, self.mp + amount)
def gain_xp(self, amount):
self.xp += amount
# Level up if XP exceeds the threshold (e.g., 100 * current level)
if self.xp >= 100 * self.level:
self.level += 1
self.xp = 0 # reset XP after leveling up
def add_item(self, item):
self.inventory.append(item)