• 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
epicpunnum

Using the Correct Data Structure

6 posts in this topic

Hello! I have been designing a level design system in Java, that allows the user to associate tiles on a tileset with a class. To do this I'm designing a dictionary file, that creates this association. However, most classes have more than one constructor. This is where I come across problems.
Originally I used a java Hashtable. The key is a String for the parameter name, and the type of the elements are Objects (for use with wrapper classes and Strings largely). However, to account for the multiple constructors, I also need to record the priority of each parameter.

Let's say that I had the following constructors:
[CODE]
public Foobar(int x, int y, String name, double gravity){
this.x=x;
this.y=y;
this.name=name;
this.gravity=gravity;
}
public Foobar(int x, int y, String name){
this.x=x;
this.y=y;
this.name=name;
this.gravity=9.8;
}
[/CODE]
I'd need to mark the x and y variables for use in the level editor, mark name as a required variable, and mark gravity as an optional variable.

I could go with 2 Hashtables each having the same exact keys, but I feel as if there must be a better way to approach this - another data structure perhaps? Any advice?
0

Share this post


Link to post
Share on other sites
I actually don't understand what you want. Can you give a use-case? Why should the two constructors produce objects which are to be differentiated somehow?
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1355869769' post='5012225']
Why should the two constructors produce objects which are to be differentiated somehow?
[/quote]
If I understand what you're asking, I simply mean that constructors are often overloaded. However, in the process of designing the level, I wanted the user to define the objects they create.
I have a Player object for instance that can turn 360 degrees. Based on the level being designed, the user may want the player to be turned 270 degrees at the start, but if they don't specify I want it to default to 90 degrees. This is an example of an option parameter, because in my code I've accounted for it, by having a constructor that [i]doesn't[/i] include an angle parameter.
But other things may be required. Wall objects are a good example of that. For any wall object (as a rectangle), you need to tell the class what its width and height are.
Both the necessity of the parameters, as well as their name and type (int, double, boolean, string, etc.) need to be recorded. Rather than break it up into 3 different, hard-to-manage arrays, or two Hashtables, I wanted to know if there was an better option in terms of data structures.
0

Share this post


Link to post
Share on other sites
[quote name='epicpunnum' timestamp='1355873979' post='5012246']
If I understand what you're asking, I simply mean that constructors are often overloaded. However, in the process of designing the level, I wanted the user to define the objects they create.
I have a Player object for instance that can turn 360 degrees. Based on the level being designed, the user may want the player to be turned 270 degrees at the start, but if they don't specify I want it to default to 90 degrees. This is an example of an option parameter, because in my code I've accounted for it, by having a constructor that doesn't include an angle parameter.
[/quote]
Yes, I understand that (though in many languages you can achieve the same thing by specifying a default value for parameters, I'm not sure Java can though). I think I understand what you want - you need objects to behave differently depending on the arguments passed to the constructor. One way to do it is to use inheritance, where all objects in your world derive from a base Entity class, and you can make different classes such as Player, Wall, Enemy, etc.. inherit from this, all with their own individual behavior, arguments, constructors, etc... Then you can just store an array of Entity instances (which may be players, walls, etc.. you don't care) and call the appropriate methods, e.g. does this Entity intersect with another (regardless of what the entities actually represent). This may not work well if your entities are too different from one another and don't share common features, and inheritance is often not the preferred solution.

So here I don't think the problem is about data structures, but about [b]design patterns[/b].
0

Share this post


Link to post
Share on other sites
There was an Item dealing with this in Effective Java (constructors with many non-essential parameters). The book proposed the builder pattern for dealing with that.

[url="http://en.wikipedia.org/wiki/Builder_pattern"]http://en.wikipedia....Builder_pattern[/url]

Though the book's example was more clear. Edited by TheChubu
0

Share this post


Link to post
Share on other sites
Thanks! With a little effort, I could rework this structure into my level designer. Might make it a bit more flexible.
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