-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.py
92 lines (76 loc) · 2.83 KB
/
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
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
import json # to get the required file
# '''This class will hold all player class and load player from json'''
def get_player():
with open("game.json", "r") as f:
jsontext = f.read()
d = json.loads(jsontext)
player = (d["player"])
return (Player(**player[0]))
class Player():
def __init__(self, name="default", hp=100, maxhp=100,
armour=0, weapon=2, items={}, room=None,
prevRoom=None, level=1, points=0):
self.pointsPerLevel = 1000 # points to increase per level
self.increasemaxhp = 10 # amount to increase max hp by
self.name = name
self.hp = hp
self.maxhp = maxhp
self.armour = armour
self.weapon = weapon
self.items = items
self.room = room
self.prevRoom = prevRoom
self.level = level
self.points = points
def isDead(self):
# determine if the player is dead
return self.hp <= 0
def SetRoom(self, roomID):
# set the new room by ID and set previous rooom
# not working - fixed was calling the function twice
old = self.room
self.prevRoom = old
self.room = roomID
def updateHP(self, damage):
# update the players HP
# if health increases use a neg num ber
self.hp = self.hp - damage
self.hp = int(self.hp)
def updateMaxHP(self, newMax):
# new max is new max number not how much to increase by
self.maxhp = newMax
def getHP(self):
# returns the health of the player
return self.hp
def getMaxHP(self):
# returns the maxium health of the player
return self.maxhp
def levelUp(self):
# increases the level of the player and increase max health
print ("in level up")
self.level = int(self.level) + 1
self.updateMaxHP(int(self.getMaxHP())+int(self.increasemaxhp))
# give player max health if they level up
self.hp = int(self.getMaxHP())
def updatePoints(self, newPoints):
# update the points fo the player and determine if they level up
self.points += int(newPoints)
increase = 1
while increase == 1:
pointsForLevel = self.pointsPerLevel*self.level
if int(self.points) >= int(pointsForLevel):
self.levelUp()
else:
increase = 0
def addItem(self, newItem):
# used to input item into dictionary
self.items[newItem] = True
def _item(self, item):
# check to see if the key is in the list and if it usuable
return self.items.get(item, False) # get the value or False
def increaseArmour(self,armour):
# increase armour amount
self.armour += armour
def increaseWeapon(self,weapon):
# increase weapon amount
self.weapon += weapon