tutorialsPythonBasic.basic.classes.class_inheritance module

An example of class inheritance.

class tutorialsPythonBasic.basic.classes.class_inheritance.Enemy(hp)[source]

Bases: builtins.object

A stupid enemy that doesn’t know how to attack, but knows how to die.

>>> stupid = Enemy(10)

Let’s hit him and see if he dies

>>> stupid.take_damage(5)
>>> stupid.alive
True

Nope, not dead yet ... let’s try again!

>>> stupid.take_damage(5)
>>> stupid.alive
False

Woohoo, down you go stupid enemy!

check_hp()[source]

If HP is too low, die.

die()[source]

Function called when the enemy dies.

take_damage(dmg)[source]

Take some damage and check your HP for death.

class tutorialsPythonBasic.basic.classes.class_inheritance.Shaman(hp)[source]

Bases: tutorialsPythonBasic.basic.classes.class_inheritance.Enemy

A smarter enemy - can do everything Enemy can, but can also heal himself.

>>> shaman = Shaman(12)

Let’s hit him and check if he was damaged

>>> shaman.take_damage(5)
>>> shaman.alive
True
>>> shaman.hp
7

Nope, not dead yet ... let’s try again!

>>> shaman.take_damage(5)
>>> shaman.alive
True
>>> shaman.hp
2

Oops, better heal yourself fast shaman!

>>> shaman.heal(20)
>>> shaman.hp
22

Wow, that was a strong heal ... better bring out the big guns!

>>> shaman.take_damage(100)
>>> shaman.hp
-78
>>> shaman.alive
False

Wait ... what are you trying to do?

>>> shaman.heal(100)
>>> shaman.hp
-78
>>> shaman.alive
False

Silly shaman, you can’t heal yourself if you’re already dead ...

heal(hp)[source]

Heal himself. Can only do that if he is alive.