Results 1 to 12 of 12
- 11-29-2011, 02:49 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Game Design: 1 Class per ability or 1 Class for all abilities
Hey everyone,
I'm fairly new to Java and even newer to Java gaming.
I'm creating a tournament-style fighter game (2D) and each character has a set of 3 abilities: Punch, Kick, and a Special. What I'm wondering is if I should create a class for each ability (in this case 3 classes) or if I should just have 1 big class for all abilities using conditional statements and arguments to determine the ability used, amount of damage, etc.
I'm sure that I can do either well enough however I'm looking at this from both an efficiency/portability/reusability standpoint as well as for best practices.
Thanks!
Scott
EDIT: I just thought of something else. perhaps it would be best to create a parent class "Abilities" which would extend to the children class "Punch", "Kick", and "Special"...
ehh.. this is so complicated.Last edited by 0026sd; 11-29-2011 at 02:53 PM. Reason: New thought
- 11-29-2011, 02:53 PM #2
Re: Game Design: 1 Class per ability or 1 Class for all abilities
Hmm, sounds like you might want to have one Ability class, then either extend it (Punch extends Ability, Kick extends Ability, Special extends Ability) or pass in parameters to set each Ability instance's data (new Ability("Punch", 3) creates an Ability called Punch that causes 3 damage, for example). In the end it's really up to you though. I wouldn't worry too much about it at this stage in the process.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-29-2011, 02:59 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Re: Game Design: 1 Class per ability or 1 Class for all abilities
Hi Kevin,
Thanks for your quick reply. Both of those options seem reasonable to me. I do feel as though the first option would be best even from an organization perspective. Perhaps it might make for easier reading later on.
Then, I'm probably over-complicated the situation. Ha.
Thanks again.
- 11-29-2011, 03:07 PM #4
Re: Game Design: 1 Class per ability or 1 Class for all abilities
It really depends on how different the Abilities are. If they simply have different names and damage values, then just having one class that you instantiate with the correct values makes sense. But if each Ability is going to be very different or have its own implementation of some method, then inheritance seems best to me. Either way, having one big class with all abilities and a bunch of if statements is probably not the way to go.
But yeah, I think it's a mistake to worry too much about doing things the right way, especially if you're relatively new to programming. No matter which way you choose, in six months you're going to cringe when you look at your code- that's simply the nature of programming. So go the way that makes the most sense to you, and you can always change it later.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-29-2011, 03:36 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
- 11-29-2011, 03:37 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Game Design: 1 Class per ability or 1 Class for all abilities
Google for "role pattern"; your abilities are the roles.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
-
Re: Game Design: 1 Class per ability or 1 Class for all abilities
Amen. This reminds me of a clever concept I've read about recently called "trace bullet" programming, the idea being that often the best way to get a complex project off of the ground is to first write quick and dirty code that does what you want, prototype if you like, and then use successive improvements to make your code prettier and of higher quality.
- 11-30-2011, 02:04 AM #8
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Re: Game Design: 1 Class per ability or 1 Class for all abilities
You know, I come from a web-programming background and I very much support this "trace bullet" style that you speak of in that context. Since I've begun programming in Java, however, I've been getting the vibe that it's something you really need to plan out meticulously before you can begin writing anything. Perhaps because switching my mind to thinking in obj-orientation is limiting me from writing these prototypes but I just feel like there are way too many things to consider when building a program.
I hope I can look at this post again in 6 months and chuckle!! How naive I was, I'll say.
- 11-30-2011, 10:59 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Game Design: 1 Class per ability or 1 Class for all abilities
I have been using OO languages and systems since the 1980s; I've seen the first versions of C++ with single inheritance and no templates and a lot of other crappy, half cooked languages. I normally play a game of CRC in my head when I have to design something. CRC (Classes Responsibilies Collaboration) is a process actually but I made it into a small mental game. If you think of it, if you have to design some software, you usually think of "it should do this and it should do that and it should do so and so". That it thing should do everything, which is not fair. Think of each and every 'it' as a separate thing, a separate object, possibly an instantiation of a separate class; but first let those 'it' things do what they have to do and give them a name, no matter which one. Make those 'it' things as simple (stupid?) as possible, i.e. no Swiss Army Knives nor magic allowed there. Add more different 'ít' things when needed and don't feel guilty when you remove other 'it' things when they're not needed.
When you can manage to let those 'it' things play the entire game, i.e. they can solve your problem for you, you have found the first stages of your solution: you have found your Classes, you have found the Collaboration of the instantiations of your classes and you have found the several Responsibilities (which 'it' does what). The fun part of it all is that you can play this game in your head, laying on your couch, smoking a sigarette, drinking a Grolsch, no fancy tools are needed; even pen and paper is optional.
You can start writing the code for your classes (the 'it' thing blueprints) and slowly by slowly you can see how your imagination becomes a true 'living' thing in that stupid computer. That's the way I do it and have done it for years.
kind regards,
JosLast edited by JosAH; 11-30-2011 at 11:02 AM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-30-2011, 01:00 PM #10
Member
- Join Date
- Sep 2011
- Posts
- 22
- Rep Power
- 0
Re: Game Design: 1 Class per ability or 1 Class for all abilities
Hi Jos,
Wonderful insight! I appreciate your mentallity about building programs and share your contempt for these stupid machines we call computers (ha ha)! Well, actually, without these computers I suppose I wouldn't have 3 out of 4 of my hobbies so I guess there's something good to say about them.
As for this CRC method I think it's something I can really get into as I'm constantly mulling over the details of a project in my head. Any time I have a second to think it's usually about whatever I'm working on so this is perfect!
To everyone who has replied to this post I thank you very much. You've helped me make a little more sense of this overwhelming world that is OO programming.
- 11-30-2011, 03:57 PM #11
Re: Game Design: 1 Class per ability or 1 Class for all abilities
It's almost creepy how similar that tracer bullet theory is to my every day approach. Make something simple that proves a theory and shows how the requirements might be accomplished, then adapt from there.
I think too many people get caught up in the mentality that they have to plan out every atom of a program before they start writing it. Even if they do come up with the perfect design, and even if their requirements don't change ten times a week, that type of person almost never actually completes a project. Meanwhile, I've put together 3 different programs that prove a concept, even if maybe not in the most well-designed way. But something that works is better than something that doesn't work (or isn't finished), no matter how well-designed the thing that doesn't work is.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-30-2011, 04:03 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Class design best practices
By vgehts in forum JDBCReplies: 4Last Post: 05-12-2011, 12:23 PM -
class design/interaction problem
By wotupduck in forum New To JavaReplies: 4Last Post: 03-20-2011, 05:54 AM -
Class Design Problems (BlackJack)
By ConMan in forum New To JavaReplies: 4Last Post: 03-16-2011, 08:38 AM -
class design
By dinosoep in forum New To JavaReplies: 3Last Post: 12-07-2009, 10:20 AM -
Pls HeLp Me (Design a class named Fan)
By faw in forum Advanced JavaReplies: 5Last Post: 04-21-2008, 07:25 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks