Object-Oriented

Let's learn Character Class and discuss some of its important methods.

Now back to our RPG, which is still pretty boring. What does it lack? Monsters and fights, of course!

Following is how a fight will be handled. If attacked, a character sees their life points decrease from the strength of the attacker. If its health value falls below zero, the character is considered dead and cannot attack anymore. Its vanquisher receives a fixed number of 1010 experience points.

First, let’s add the capability for our characters to fight one another. Since it’s a shared ability, we define it as a method named attack() in the Character class. The attack() method checks the health of two fighting characters.

Get hands-on with 1400+ tech skills courses.