Results 1 to 6 of 6
Thread: Dynamic Subclasses?
- 11-07-2010, 12:41 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 43
- Rep Power
- 0
Dynamic Subclasses?
I'm working on a game that uses tiles. It's setup so players can make their own maps with the default tiles given. I want to make it so users can can create their own tiles with their own properties in a text file and be loaded to the game with all of its properties as a tile subclass. Is it possible to create subclasses like this?
- 11-07-2010, 12:50 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
More than it could be an object isn't it? What you really mean by dynamic classes?
- 11-07-2010, 01:03 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 43
- Rep Power
- 0
Ok, here is an example of some tiles programmed normally-
But what is a user wants to make a tile called "Trampoline" for his/her map that has a bounce property of 20. So that when a user comes down on it they will bounce. Can I dynamically generate this subclass based on that property?Java Code:public class Tile { Color c; Image texture; int alpha; int bounce; boolean solid; boolean buildable; boolean smoothDraw; etc... public Tile() { c = new Color(Color.BLACK); texture = null bounce = 0; etc... } } public class Grass extends Tile { public Grass() { c = new Color(Color.GREEN); etc... } } public class Dirt extends Tile { etc...
I know it's possible to make a Tile object and just set all these values one by one in a loop. But a map may have tens of thousands of tiles. Is that the only way it can be done or can I dynamically make the "Trampoline" subclass someway and add it to the Tile grid?
-
One solution is to rather than making a bunch of classes, make one Tile class that is flexible enough to change properties. And why not change the values in a loop? Even if you have many tiles this can work.
- 11-07-2010, 01:26 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 43
- Rep Power
- 0
That's what I originally thought but I also thought that was a little primitive. So I guess I will go with that.
- 11-07-2010, 01:28 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, in a one class make possible to change required parameters according to your design. Then you may need to deals with additional values in a situation, if any. Otherwise only thing you've to do is assign appropriate values.
Similar Threads
-
Lost with subclasses
By vinyacam in forum New To JavaReplies: 3Last Post: 05-09-2010, 07:12 PM -
Generics and subclasses
By Sven in forum Advanced JavaReplies: 1Last Post: 12-22-2008, 06:06 PM -
Main class and subclasses
By rosh72851 in forum New To JavaReplies: 5Last Post: 11-19-2008, 06:16 PM -
help needed with methods in subclasses
By uncopywritable in forum New To JavaReplies: 4Last Post: 08-01-2007, 01:47 PM -
Hibernate subclasses
By Ed in forum JDBCReplies: 2Last Post: 07-02-2007, 04:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks