-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.py
More file actions
49 lines (41 loc) · 1.34 KB
/
Player.py
File metadata and controls
49 lines (41 loc) · 1.34 KB
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
import json
from kivy.uix.screenmanager import Screen
class Player:
def __init__(self):
self.hp = 0
self.str = 0
self.int = 0
self.spt = 0
self.end = 0
self.golden_coins = 0
self.inventory = {}
#writes the character sheet to the json file to save it for l8r
def write_to_json(self):
stats = {}
stats['Strength'] = self.str
stats['Intelligence'] = self.int
stats['Endurance'] = self.end
stats['Spirit'] = self.spt
stats['golden_coins'] = self.golden_coins
with open('player.json','w') as outfile:
json.dump(stats,outfile)
#updates the character sheet from the json file
def read_from_json(self):
with open('player.json') as json_file:
stats = json.load(json_file)
self.str = stats['Strength']
self.int = stats['Intelligence']
self.end = stats['Endurance']
self.spt = stats['Spirit']
self.golden_coins = stats['golden_coins']
def increase_stat(self,stat,value):
self.read_from_json()
if stat == 'Strength':
self.str += value
elif stat == 'Intelligence':
self.int += value
elif stat == 'Endurance':
self.end += value
else:
self.spt += value
self.write_to_json()