Results 1 to 4 of 4
Thread: classes and methods
- 06-03-2012, 01:50 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 25
- Rep Power
- 0
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.Last edited by louboulos; 06-03-2012 at 01:54 PM.
- 06-03-2012, 02:25 PM #2
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
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?
- 06-03-2012, 02:28 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-03-2012, 02:54 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
What classes and methods to use?
By chyrl in forum Advanced JavaReplies: 21Last Post: 06-20-2010, 12:45 PM -
using methods between classes
By soccer_kid_6 in forum New To JavaReplies: 2Last Post: 04-18-2010, 03:14 AM -
Classes and main methods?
By CyberFrog in forum New To JavaReplies: 17Last Post: 05-26-2009, 04:47 AM -
Classes and Methods help
By border9 in forum New To JavaReplies: 5Last Post: 01-30-2009, 06:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks