Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help!! python need the of the class hero assignment use the bold code as

ID: 3834098 • Letter: P

Question

please help!! python need the of the class hero assignment use the bold code as a guide thankyou..

# Alien Blaster

# Demonstrates object interaction

class Player(object):

""" A player in a shooter game. """

def blast(self, enemy):

print("The player blasts an enemy. ")

enemy.die()

class Alien(object):

""" An alien in a shooter game. """

def die(self):

print("The alien gasps and says, 'Oh, this is it. This is the big one. "

"Yes, it's getting dark now. Tell my 1.6 million larvae that I loved them... "

"Good-bye, cruel universe.'")

def main():

print(" Death of an Alien ")

hero = Player()

invader = Alien()

hero.blast(invader)

  

# main

main()

input(" Press the enter key to exit.")

use this code as guide

                                

Class Hero

Attributes

name, set so it defaults to ‘Arnold’, but can be reset to some other name.

health, initialized to 10

shield, initialized to 10, but is not used in this game.

life, initialized to 1

            Methods:

Constructor,     init     (), takes a string parameter that defaults to ‘Arnold’.

blast(), takes an player object argument to communicate that the enemy has been hit. Blast() implements an immediate call to the enemy die() method.

die(), no arguments, decrements health. Decrements lives, when health gets to 0. When lives is 0, the soldier dies.

Class Alien

Same as Hero

Main()

Game over when one combatant is dead.

Explanation / Answer

PROGRAM CODE:

import sys

class Alien(object):
  
   def __init__(self):
       self.name = 'Arnold'
       self.health = 10
       self.shield = 10
       self.life = 1
   def blast(self, enemy):
       enemy.die()
   def die(self):
       print('Soldier blasts the alien')
       self.health = self.health-1;
       self.life = 0
       if(self.health == 0 and self.life == 0):
           print('Alien is dead')
           sys.exit()

class Hero(object):
   def __init__(self):
       self.name = 'Arnold'
       self.health = 10
       self.shield = 10
       self.life = 1
   def blast(self, enemy):
       enemy.die()
   def die(self):
       print('Alien blasts the soldier')
       self.health = self.health-1;
       self.life = 0
       if(self.health == 0 and self.life == 0):
           print('Soldier is dead')
           sys.exit()

def main():
   print(" Death of an Alien ")
   hero = Hero()
   invader = Alien();
   hero.blast(invader)
   hero.blast(invader)
   hero.blast(invader)
   invader.blast(hero)
   hero.blast(invader)
   hero.blast(invader)
   invader.blast(hero)
   hero.blast(invader)
   invader.blast(hero)
   invader.blast(hero)
   hero.blast(invader)
   invader.blast(hero)
   invader.blast(hero)
   hero.blast(invader)
   invader.blast(hero)
   hero.blast(invader)
   invader.blast(hero)
   hero.blast(invader)
   invader.blast(hero)

# main
main()
input(" Press the enter key to exit.")

OUTPUT: