Results 1 to 12 of 12
Like Tree3Likes
  • 1 Post By KevinWorkman
  • 1 Post By 0026sd
  • 1 Post By JosAH

Thread: Game Design: 1 Class per ability or 1 Class for all abilities

  1. #1
    0026sd is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default 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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,988
    Rep Power
    9

    Default 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!

  3. #3
    0026sd is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by KevinWorkman View Post
    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.
    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.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,988
    Rep Power
    9

    Default 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.
    Fubarable likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    0026sd is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by KevinWorkman View Post
    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.
    Wonderful. Thank you for taking the time to respond -- it helped a lot.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Google for "role pattern"; your abilities are the roles.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by KevinWorkman View Post
    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.
    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.

  8. #8
    0026sd is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by Fubarable View Post
    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.
    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.
    Fubarable likes this.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by 0026sd View Post
    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.
    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,

    Jos
    Last edited by JosAH; 11-30-2011 at 11:02 AM.
    0026sd likes this.
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    0026sd is offline Member
    Join Date
    Sep 2011
    Posts
    22
    Rep Power
    0

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by JosAH View Post
    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,

    Jos
    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. #11
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,988
    Rep Power
    9

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Quote Originally Posted by Fubarable View Post
    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.
    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!

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: Game Design: 1 Class per ability or 1 Class for all abilities

    Refactorings are of great help here (see Martin Fowler)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Class design best practices
    By vgehts in forum JDBC
    Replies: 4
    Last Post: 05-12-2011, 12:23 PM
  2. class design/interaction problem
    By wotupduck in forum New To Java
    Replies: 4
    Last Post: 03-20-2011, 05:54 AM
  3. Class Design Problems (BlackJack)
    By ConMan in forum New To Java
    Replies: 4
    Last Post: 03-16-2011, 08:38 AM
  4. class design
    By dinosoep in forum New To Java
    Replies: 3
    Last Post: 12-07-2009, 10:20 AM
  5. Pls HeLp Me (Design a class named Fan)
    By faw in forum Advanced Java
    Replies: 5
    Last Post: 04-21-2008, 07:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •