0
Python Intermediate "Shooting Game" challenge answer
Please i need help on this challenge i have been stuck on it for a while and i need help or a answer preferably a answer.
4 Réponses
+ 5
This worked for me :👇
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
elif x == "laser":
a.hit()
else:
m.hit()
+ 1
Share your attempt
+ 1
class Enemy:
name = ""
lives = 0
def __init__(self, name, lives):
self.name = name
self.lives = lives
def shooting(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 shooting(self):
super().shooting()
class Alien(Enemy):
def __init__(self):
super().__init__('Alien', 5)
def shooting(self):
super().shooting()
m = Monster()
a = Alien()
while True:
x = input()
if x == 'exit':
break
elif x == 'gun':
m.shooting()
elif x == 'laser':
a.shooting()
0
This worked for me :👇
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
elif x == "laser":
a.hit()
else:
m.hit()