- 1
Trying to solve the shooting game project
class Enemy: name = "" lives = 0 def __init__(self, name, lives): self.name = name self.lives = lives def hit(self): self.lives -= 1 if self.lives <= 0: print(self.name + ' killed') else: print(self.name + ' has '+ str(self.lives) + ' lives') class Monster(Enemy): def __init__(self): super().__init__('Monster', 3) class Alien(Enemy): def __init__(self): super().__init__('Alien', 5) m = Monster() a = Alien() while True: x = input() if x == 'exit': break Here is my code I don't know the next step to tale from here
7 Answers
+ 3
class Enemy:
name = ""
lives = 0
def __init__(self, name, lives):
self.name = name
self.lives = lives
def hit(self):
self.lives -= 1
if self.lives <= 0:
print(self.name + ' killed')
else:
print(self.name + ' has '+ str(self.lives) + ' lives')
class Monster(Enemy):
def __init__(self):
super().__init__('Monster', 3)
def hit(self):
super().hit()
class Alien(Enemy):
def __init__(self):
super().__init__('Alien', 5)
def hit(self):
super().hit()
m = Monster()
a = Alien()
while True:
x = input()
if x == 'exit':
break
elif x == 'laser':
a.hit()
elif x == 'gun':
m.hit()
https://code.sololearn.com/cheRw6L9neDj/?ref=app
+ 1
while True:
x = input()
if x == 'exit':
break
elif x == 'laser':
a.hit()
elif x == 'gun':
m.hit()
0
Hey, looks fine, what do you want to do next?
0
It still did not work it gave eof error
0
Luk i want to
2. Complete the while loop that continuously takes the weapon of choice from user input and call the corresponding object's hit() method.
0
Hey some one post the correct answer
0
Can someone post the right answer of the shooting game, i have been stuck for 2 weeks and nobody posted the right one