-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameData.py
72 lines (58 loc) · 1.4 KB
/
gameData.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
#!/usr/bin/python
# -*- coding: utf8 -*-
class Item:
weight = 0.1
baseCost = 2
baseSold = 1
itemId = 0
def __init__(self, itemId):
self.itemId = itemId
class Inventory:
def __init__(self):
self.clear()
def clear(self):
self.items = {}
def addItem(self, itemId, number):
if itemId in self.items:
self.items[itemId] += int(number)
else:
self.items[itemId] = int(number)
def get(self):
keys = self.items.keys()
keys.sort()
res = ""
for key in keys:
res = res + str(key) + "," + str(self.items[key]) + ";"
return res
def set(self, itemString):
self.items = {}
itemString = itemString.strip()
for elem in split(itemString, ';'):
item = elem.split(',')
if len(item)==2:
self.addItem(item[0].strip(), item[1].strip())
class Being(object):
def __init__(self, name):
self.name = name
self.hp = 1
self.hpMax = 1
self.carac = {}
for carac in ["str", "dex", "cons", "wil"]:
self.carac[carac] = 1
self.skills = {}
self.xp = {}
def heal(self, n):
self.hp += n
# keep hp between 0 and hpMax
self.hp = min(max(self.hp, 0), self.hpMax)
def takeDamage(self, n):
self.hp -= n
self.hp = min(max(self.hp, 0), self.hpMax)
def getCarac(self, caracName):
if caracName in self.carac:
return self.carac[caracName]
return 0
def getSkill(self, skillName):
if skillName in self.skills:
return self.skills[skillName]
return 0