forked from Elegy-Composer/InforJourney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.py
65 lines (54 loc) · 1.83 KB
/
Entity.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
from random import uniform
from Item import Armor, Weapon
class Entity:
def __init__(self, name, hp, atk, dfd):
self.name = name
self.hp = hp
self.atk = atk
self.dfd = dfd
def fight(self, B):
A = self
a_dmg = A.atk - B.dfd
b_dmg = B.atk - A.dfd
print(a_dmg, b_dmg)
print(A.name,A.atk,A.dfd)
print(B.name,B.atk,B.dfd)
if(hasattr(A,"weapon")):
a_dmg+=A.weapon.atk+A.armor.atk
b_dmg-=A.weapon.dfd+A.armor.dfd
if(hasattr(B,"weapon")):
b_dmg+=B.weapon.atk+B.armor.atk
a_dmg-=B.weapon.dfd+B.armor.dfd
print(a_dmg, b_dmg)
a_dmg = max(a_dmg,0)
b_dmg = max(b_dmg,0)
if a_dmg == 0 and b_dmg == 0:
print("垃圾互打")
return;
fight_str = ""
while 1:
# Attack Phase
dmg = round(a_dmg * uniform(0.9, 1.1))
B.hp -= dmg
fight_str += "{} 攻擊 {},{} 剩下 {} 滴血\n".format(A.name, B.name, B.name, max(B.hp, 0))
# HP Judge Phase
if B.hp <= 0:
return fight_str
A, B = B, A # Malignant
a_dmg, b_dmg = b_dmg, a_dmg
class Monster(Entity):
def __init__(self, name, atk, dfd, hp, exp, coin):
super(Monster, self).__init__(name, hp, atk, dfd)
self.exp = exp
self.coin = coin
class Boss(Monster):
def __init__(self, name, atk, dfd, hp, exp, coin, drop_item):
super(Boss, self).__init__(name, atk, dfd, hp, exp, coin)
if drop_item[0]:
self.drop_item = (Weapon(drop_item[0]), Armor(drop_item[1]))
else:
self.drop_item = (None, None)
def drop(self):
dropped = self.drop_item
self.drop_item = (None, None)
return dropped