-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattack-game
More file actions
43 lines (33 loc) · 944 Bytes
/
attack-game
File metadata and controls
43 lines (33 loc) · 944 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
42
class Game:
life=3
def attack(self):
self.life-=1
def defensive(self):
self.life-=0;
def lifes(self):
return( self.life )
game1 = Game()
print(" Instructions to play the game \n")
print(" 1. Attack \n")
print(" 2. Defensive \n")
while True:
try:
x=int(input())
if(x==1):
game1.attack()
lives= game1.lifes()
if(lives <= 0 ):
print "Game Over"
break
else:
print( str(lives) + " Lives left" )
elif(x==2):
game1.defensive()
lives= game1. lifes()
print( str(lives) + " Lives left" )
else:
print(" Only 1 and 2 are acceptable inputs " )
except NameError:
print(" Only 1 and 2 are acceptable inputs " )
except SyntaxError:
print(" Only 1 and 2 are acceptable inputs " )