-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtankgame.py
More file actions
executable file
·42 lines (29 loc) · 899 Bytes
/
Copy pathtankgame.py
File metadata and controls
executable file
·42 lines (29 loc) · 899 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
from tank import Tank
tanks = { 'r': Tank( 'Rutgers'), 'p': Tank( 'Princeton' ), 'n' : Tank( 'NJIT') }
alive_tanks = len(tanks)
while alive_tanks > 1 :
print
for tank_name in sorted( tanks.keys()):
print tank_name, tanks[tank_name]
attacker = raw_input("Who fires ? ").lower()
target = raw_input("Who gets hit ? ").lower()
try :
attacker_tank = tanks[attacker]
target_tank = tanks[target]
except KeyError, name:
print "Tank id not found in dictionary !" ,name
continue
if not attacker_tank.alive or not target_tank.alive:
print "One of the tanks in combat are already dead!"
continue
print
print "*" * 30
attacker_tank.fires_at(target_tank)
if not target_tank.alive:
alive_tanks -= 1
print "*" * 30
for tank in tanks.values():
if tank.alive:
print tank.name, "has survive the battle!"
break