-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacters.py
More file actions
68 lines (56 loc) · 1.44 KB
/
characters.py
File metadata and controls
68 lines (56 loc) · 1.44 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import random
class Character(object):
def __init__(self,health,ammo):
self.health=health
self.ammo=ammo
def hit_enemy(self):
if self.ammo>0:
damage=random.random()
self.ammo-=0.2*damage
else:
damage=0
return damage
def take_hit(self,damage):
self.health-=damage*self.health
class Zombie(Character):
def __init__(self,number):
self.max_health=1
self.max_ammo=1
Character.__init__(self,self.max_health,self.max_ammo)
self.number=number
def die(self):
if self.health<=0.25:
return True
else:
return False
class Fighter(Character):
def __init__(self,name):
self.max_health=10
self.max_ammo=10
Character.__init__(self,self.max_health,self.max_ammo)
self.name=name
self.score=0
def move(self):
chance=random.random()
if chance<0.5:
return False
else:
return True
def reload(self):
gap=self.max_ammo-self.ammo
self.ammo+=gap*random.random()
def restore(self):
wound=self.max_health-self.health
self.health+=wound*random.random()
def flee(self,zombies):
del zombies[:]
def shoot(self,zombie):
if self.ammo>0:
zombie.take_hit(self.hit_enemy())
if zombie.die():
self.score+=1
return True
else:
return False
def status(self):
return (self.health,self.ammo)