-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtank.py
More file actions
executable file
·42 lines (27 loc) · 753 Bytes
/
Copy pathtank.py
File metadata and controls
executable file
·42 lines (27 loc) · 753 Bytes
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
#!/usr/bin/python -tt
class Tank(object):
def __init__(self, name):
self.name = name
self.alive = True
self.ammo = 10
self.armor = 100
def __str__(self):
if self.alive:
return "%s (%i armor, %i shells)" % (self.name, self.armor, self.ammo)
else:
return "%s (DEAD)" % self.name
def fires_at(self, enemy):
if self.ammo >=1:
self.ammo -=1
print self.name, "fires on ", enemy.name
enemy.took_damage()
else:
print self.name, "is out of ammo !"
def took_damage(self):
self.armor -= 20
print self.name , " just got hit with a shell!"
if self.armor <= 0 :
self.killed()
def killed(self):
self.alive = False
print self.name, " is dead !"