forked from DAZHAdazha/No-names-land
-
Notifications
You must be signed in to change notification settings - Fork 0
/
消耗品生成器.py
67 lines (50 loc) · 1.9 KB
/
消耗品生成器.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
import json
class Drug:
def __init__(self, name):
self.name = name
def drug_capacity(self,num = 0):
self.size = 1
self.num = num
def drug_effect(self, attack, defence, health, speed, magic):
self.attack = attack * self.size
self.defence = defence * self.size
self.health = health * self.size
self.speed = speed * self.size
self.magic = magic * self.size
def change_drug_dic(self, drug_list):
dic = {'name': self.name, 'attack': self.attack, 'defence': self.defence, 'health': self.health, 'magic': self.magic,
'speed': self.speed, 'num': self.num}
drug_list.append(dic)
def create_drug(self, attack, defence, health, speed, magic, drug_list):
self.drug_effect(attack, defence, health, speed, magic)
self.change_drug_dic(drug_list)
def use_drug(drug, character):
character.cur_ability(drug.attack, drug.defence, drug.health, drug.magic, drug.speed)
drug.num -= 1
def get_drug(drug, num=1):
drug.num += num
def load_drug(contents, drug_list):
for i in contents['drug']:
dr = Drug(i['name'])
dr.health = i['health']
dr.speed = i['speed']
dr.magic = i['magic']
dr.defence = i['defence']
dr.attack = i['attack']
drug_list.append(dr)
def down_drug(contents, drug_list):
contents['drug'] = drug_list
name = str(input("name: "))
with open("fileSave.json", 'r', encoding='utf-8') as f:
contents = json.load(f)
dr = Drug(name)
dr.drug_capacity(0)
attack = int(input("attack: "))
defence = int(input("defence: "))
health = int(input("health: "))
speed = int(input("speed: "))
magic = int(input("magic: "))
dr.create_drug(attack, defence, health, speed, magic, contents['drug'])
with open("fileSave.json", 'w', encoding='utf-8') as f:
contents = json.dumps(contents, indent=4, ensure_ascii=False)
f.write(contents)