-
classes and methods
Hello! I have a rather complicated question...
I am trying to make a very simple game. I have 2 classes. The first is called "Warrior" and the second "Monster". Each one, appart from the getters and setters, has a method called "doAttack()" which obviously removes life from the Warrior or the Monster.
My question is: How can I make this method to "work" for every random Warrior class, a potential user may create? Because as of now I have to create a new warrior object in the doAttack() method in order to make it "know" which character's life should decrease. Let me give you an example.
Let's say that a user creates a new warrior named: Warrior mywar = new Warrior(100,50,50) .
I want the monster's doAttack() method to work like this: monster.doAttack(mywar)
I hope you understand my question.
Thanks in advance.
-
Re: classes and methods
That is a bit hard to answer since I don't know how the game works. Maybe you can explain it thoroughly?
-
Re: classes and methods
Think in terms of interfaces; an A attacks a B where A and B are interfaces; your concrete classes implement interface A and/or B.
kind regards,
Jos
-
Re: classes and methods
never mind i got it. I should have put doAttack(Warrior s) for example when defining the method.