Help Understanging This Python Code


Recommended Posts

I am having a tough time understanding what is going on in this following code

class Player(object):

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

   def blast(self, enemy):

       print "The player blasts an enemy.\n"

       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. \n" \

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

             "Good-bye, cruel universe.'"

# main

print "\t\tDeath of an Alien\n"


hero = Player()

invader = Alien()

hero.blast(invader)

in particular this line

hero.blast(invader)

how is the object invader interacting the the blast method?

Edited by shanenin
Link to post
Share on other sites

The blast() method takes takes an alien (or whatever) as its sole argument, prints a message, and then calls alien's die() method. Not much more too it.

Edited by jcl
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...