Jump to content

  • Log In with Google      Sign In   
  • Create Account


Objects with Collections with Objects with Collections...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Theis_Bane   Members   -  Reputation: 312

Like
0Likes
Like

Posted 09 July 2012 - 09:20 PM

Okay, this seems like it should be relatively obvious, but days and days of programming have made my head into jello. I'm currently building a text-based game with my own version of a component-based entity system. I say my own because I'm trying to take what little I know about it and work my way though the problems as I go. I've got my entities contained within one another as follows:

World.List(Zone).List(Area).List(Feature).List(Components).Method and Properties

World - Overall game world.
Zone - A house.
Area - A specific room.
Feature - A door.
Component - Openable.
Property - IsOpen.

Now, this makes sense to me. However, I can't seem to wrap my head around how to efficiently access and change the address of the part of the world I'm want to. Especially considering function calls and whatnot. Like I said, I'm sure this isn't the problem I'm making it out to be, my head just hurts.

Edited by Theis_Bane, 09 July 2012 - 09:43 PM.


Sponsor:

#2 DevLiquidKnight   Members   -  Reputation: 834

Like
0Likes
Like

Posted 11 July 2012 - 06:26 AM

Why don't you simply use OOP for this instead of storing it as a bunch of collections?

#3 Codarki   Members   -  Reputation: 462

Like
0Likes
Like

Posted 11 July 2012 - 07:48 AM

how to efficiently access and change the address of the part of the world?

Can you expand on that, and we (and possibly you aswell) get clearer picture what you're after?

Access from where? Do you have a single class (or function) which is requiring access to everywhere?

Change what address? Does this mean modifying the current world?

#4 Rld_   Members   -  Reputation: 1379

Like
0Likes
Like

Posted 12 July 2012 - 02:59 AM

I'm not sure how your world/game is constructed, but with your entities being accessible like that, I get the feeling the player knows the world(zone) with everything in it. What you can do is make make a class for each object like this: (pseudocode)

[source lang="cpp"]class World{ List Zones<Zone>; // list of zones in this world}class Zone{ List Areas<Area> // list of areas in this zone}class Area{ List Features<Feature> // list of features in this area}class Feature{ //whatever properties you want/need or components, you get the idea}// Now you can access individual classes more easilyint main{ Feature door = World.zone.area.feature // You can let the player know beforehand in what part of the world/zone/area he is in at the moment so you only have to access the features of that part, with its components/properties.}[/source]
Hope this clears it a bit up for you.

#5 Theis_Bane   Members   -  Reputation: 312

Like
0Likes
Like

Posted 12 July 2012 - 12:16 PM

Basically, what I've got is a single BaseEntity class that possesses a Name and ID property. From there, I have more specialized Entity classes that inherit from this class. These are my components. I have an EntityCollection Class that is designed to hold a list of components that collectively represent an area or object.

An item is the world might have a collection containing - IsObtainable(a component telling the game that the player can pick this up), IsWieldable(a component telling the game that the player can use this as a weapon), Points(a component telling the game that obtaining this item gives the player a certain number of points). Each object is also a component, and is a member of another object's EntityCollection all the way up until the world object.

I am going to have a Manager class which will look at where the player is, describe the area, take in and parse a line of commands, manipulate the data, and present the results. What I'm guess is that once the game world is completely loaded into my World object, I basically just pass small parts of it to functions and methods for processing. I think. It's a lot to get my head around.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS