• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Kk1496

java Constructor parameters

16 posts in this topic

I am trying to create a text adventure in java. This is my first large program so, i may be going about it the wrong way. I planed to create a super class for generic items that parents sub classes for different types of items like health items and equipable items.

 

I have a basic class called item that has id, name, description, and weight variables. I have sub classes that add other attributes. do i need to include the super class's variables in the parameter for the subclass constructor? if not how would i set the super class's variables when I instantiate the subclass?

0

Share this post


Link to post
Share on other sites
@Glass_knife: so, if I continue with my inheritance craziness, I would have to feed a long list of args into the sub-class constructor and feed some of those into a super constructor.

Are you trying to say that instead I should just make different stand alone classes for each item? And, is this due to my level of experience with java or the scope of the project?
0

Share this post


Link to post
Share on other sites
@SeraphLance: I guess what I meant was that I could make a class for all items with all possible attributes and make different constructors - picking and choosing which instance vars to use based on the type of item.
0

Share this post


Link to post
Share on other sites

I would have to agree with Glass_Knife, you should favor composition over monolithic inheritance trees. Basically what that means is that an in game object(or entity) is made up of mutiple components. So for example if you had a Iron sword, it could have a wieldable component, a sword component, an iron component, it might even have a firey enchantment component.

 

You could code all of this into your game, but I'd suggest making it as data-driven as possible. So perhaps you could read from a text file or an XML file what each item is built of and your game would populate the world with those items. This is just a suggestion though, on smaller scale projects this may be overkill.

 

There's lots of good reading available on the topic of Entity-Component systems. There are a few articles on this site that go over how they work, a simple google search for "Entity-Component systems" should give you quite a bit to chew on for now.

 

Another good resource is the Artemis framework, so that might be something to look into(Although I'd say it's a bit beyond the scope of this project).

2

Share this post


Link to post
Share on other sites


I would have to agree with Glass_Knife, you should favor composition over monolithic inheritance trees. Basically what that means is that an in game object(or entity) is made up of mutiple components. So for example if you had a Iron sword, it could have a wieldable component, a sword component, an iron component, it might even have a firey enchantment component.

 

This is another way to go.  I'm actually not suggesting any design up front.  Just code up what you need doing the simplest thing possible (i.e. no inheritance or composition or anything).  When you find you keep writing the same stuff over and over again, refactor to common code.  This may be a base class with child classes, or it may be objects composed of other objects.

2

Share this post


Link to post
Share on other sites

 


I would have to agree with Glass_Knife, you should favor composition over monolithic inheritance trees. Basically what that means is that an in game object(or entity) is made up of mutiple components. So for example if you had a Iron sword, it could have a wieldable component, a sword component, an iron component, it might even have a firey enchantment component.

 

This is another way to go.  I'm actually not suggesting any design up front.  Just code up what you need doing the simplest thing possible (i.e. no inheritance or composition or anything).  When you find you keep writing the same stuff over and over again, refactor to common code.  This may be a base class with child classes, or it may be objects composed of other objects.

 

 

That's probably the best way to go, what I described may very well be overkill for this particular project. You should probably go with the simplest possible approach to get what you need to do done, there's no need to over complicate things.

0

Share this post


Link to post
Share on other sites


 When you find you keep writing the same stuff over and over again, refactor to common code.  This may be a base class with child classes, or it may be objects composed of other objects.

 

that's what i was trying to avoid. I was trying to anticipate what I would need to re write.

 

I looked up "is - a" and "has a" relationships here: 

 

It seems to me that Health item and equipable items could share common attributes so it "is a " type of item.

 

I was also thinking of making a large item class and picking and choosing which values to use in different constructors (not sure if i mentioned this before). Is this what some of you are talking about?

0

Share this post


Link to post
Share on other sites


that's what i was trying to avoid. I was trying to anticipate what I would need to re write.

 

Number of times I have designed an API and had the end result match the design = 0.

 

As an example, let us say you have an Equipable base class, and then a HealthItem which "is a" Equipable item.  Later you come up with different kinds of PowerUps, that aren't equipable but bestow some temporary benefit.  Then you make a MagicBooster that "is a" PowerUp.

 

Months later you try to create a MegaHealthBooster, that is a HealthItem and is a MagicBooster.  But now you have multiple inheritance, which is bad in C++ and not even allowed in many other languages.  To get around this, you'll have to redesign your classes or create some silly hacks that will cause weird bugs down the line.  

 

Just be aware that this will be an issue if you take the "BaseClass / ChildClass" design.

 

If you had game objects that are composed of other objects, then a MHB that contains a HealthItem and a MagicBooster is easier.

2

Share this post


Link to post
Share on other sites

@Glass_Knife: i did run into problems with that inheritance system i was using. I intended to load the items into a room by a single list. I didn't think this could be done because i had separate classes for HealthItems and Equipable items (by equipable i meant weapons or tools).I don't think i could reference both types of items by just making a list of items.

 

I tried the other way I had proposed. I ran into a problem where both Health item constructor and equipable item constructor had the same type and number of parameters.

 

I'm all out of ideas now :(

suggestions anyone?

0

Share this post


Link to post
Share on other sites

I think someone might have suggested this before and i finally understand it. I created an item class with basic attributes for an item and created another class for Health items where i am making an item object ass one of the health item's variables

0

Share this post


Link to post
Share on other sites

I ran into another problem where. I created item class with basic attributes for an item and created another class for each type of item that consists of a basic item object. so, in order to keep all the items i needed to store them in a list or array of objects. My problem now is that when i can't reference functions for the objects in the array.

0

Share this post


Link to post
Share on other sites

@Aldacron O-oh! I see, so I was trying to stick the gameObject inside of the component instead of the component into the game object!

 

Thank you to all who have participated in the topic!

0

Share this post


Link to post
Share on other sites

Ok. so, i tried creating an item class with the basic things I wanted for every item and a list to load the necessary components into. I created a print function to print all of those attributes. Then, i moved on to the first component. I created variables for the things that i wanted to vary in this type of item. However, I don't know how to make the print function work for the components. I am extremely confused about how to make the classes interact in general. How do i reference the item when i'm trying to print out all of it's attributes.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0