V
V
Vadim kyklaed2016-12-16 23:42:51
OOP
Vadim kyklaed, 2016-12-16 23:42:51

How to properly build application structure (python)?

Hello everyone, I ran into a problem, I'm learning OOP and for this I write a simple text RPG, I have the following structure:
class hero (hero): lives, strength, dexterity
monster class (monst): lives, strength, dexterity,
they are inherited by a class with damage calculation strike (fightsys) - it calculates the damage caused by a monster or a hero depending on where the blow goes, head, body, arms, legs
class (fight) inherits fightsys
, it already processes the logic of the battle, a person plays for the hero and chooses which part to hit and the monster answers randomly.
so the problem is that it doesn't work. that is, it’s not clear why it doesn’t work, the very first check in the fight class that the monster and the hero have full hp ends in failure, the hero’s hp normally works out and the monster’s hp doesn’t come, if it doesn’t go further than its class at all. although everything is done 1 in 1 with the hero class.
What is the problem ? Or am I building the application incorrectly at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Senka Chekanov, 2016-12-17
@Sencho_Pens

You are confusing classes with functions.
It seems to me that it is worth doing this:
class Person with the hit(self, enemy, limb) method, where enemy is an instance of Person, and then you can describe all the impact logic in the method.
Accordingly, Hero and Monster are inherited from Person, and in Hero define the fight method, which would ask the user where and whom to hit, and would use self.hit (whom, where).
In general, don't produce many classes and inheritances, and write class names in CamelCase.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question