By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

How to "kind of" make shared an object? :)

P: n/a
I have this classes tree

GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects

Now each Squad or Units have to know about data on it's Map

Say I have Game1 and Game 2
Game2 have different map than Game1
any unit1_1 of branch Game1 need to know about Map1
any unit1_2 of branch Game2 need to know about Map2

How to accomplish that?

Should I pass to Unit1_1 the Game1 instance?

I whould like the Map1 shared to all Game1 children objects somehow..the
same with Map2 and Game2

Right now I keep passing the map arround each time I need it way down to a
unit that move or do stuffs

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
What I want to know is if it is possible to make some kind of xml tree
walking, so I can go up and access any ancestor of a node... i my case nore
is a reference to a class instance

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
I have this classes tree

GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects

Now each Squad or Units have to know about data on it's Map

Say I have Game1 and Game 2
Game2 have different map than Game1
any unit1_1 of branch Game1 need to know about Map1
any unit1_2 of branch Game2 need to know about Map2

How to accomplish that?

Should I pass to Unit1_1 the Game1 instance?

I whould like the Map1 shared to all Game1 children objects somehow..the
same with Map2 and Game2

Right now I keep passing the map arround each time I need it way down to a
unit that move or do stuffs

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #2

P: n/a
On Wed, 14 Jan 2004 11:14:32 +0200, Crirus wrote:

GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects


I don't know fully what you are designing, but to my mind, Player should
not be on the same level as Game but rather a sub level of game:

GameManager
Game
Map
Player
Squads
Units

Player, to me is an element of a Map. It seems like it would be a child of
map. A GameManager contains Games which contain maps which contain players
which have squads of units.

If this is the case, then a single unit can traverse up through it parents
to get the map info.

Just my thoughts.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #3

P: n/a
the players are indeed childs of game.. was a TAB missing there
Map is a separate class only with data of the terrain
Players join to game not to map in my design

How to traverse up such a graph?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1f******************************@40tude.net.. .
On Wed, 14 Jan 2004 11:14:32 +0200, Crirus wrote:

GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects

I don't know fully what you are designing, but to my mind, Player should
not be on the same level as Game but rather a sub level of game:

GameManager
Game
Map
Player
Squads
Units

Player, to me is an element of a Map. It seems like it would be a child

of map. A GameManager contains Games which contain maps which contain players which have squads of units.

If this is the case, then a single unit can traverse up through it parents
to get the map info.

Just my thoughts.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #4

P: n/a
On Thu, 15 Jan 2004 09:47:30 +0200, Crirus wrote:
the players are indeed childs of game.. was a TAB missing there
Map is a separate class only with data of the terrain
Players join to game not to map in my design

How to traverse up such a graph?


My only thought on that would be that each object would have a "parent"
property or perhaps a "ContainedBy" proprty that contains a reference to
the object that contains them. As each object is created, its parent
object could be set. I don't know how a heirarchy like this might affect
performance.

So a Unit could get the map data by using something like

Squad = Unit.Parent 'Get the squad the unit is in
Player = Squad.Parent 'Get the Player that owns the squad
Map = Player.Parent 'Get the map object for the player
Game = Map.Parent 'Get the game object for that map

There may be better ways, though

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #5

P: n/a
Yes, that can be a solution, or even better to make a parent or grand parent
reference only in the classes that need it....
But I was wander if there could be a way to get this automatically without
my concern, but I guess a child class have no ideea about a parent that hold
it's reference
--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:nc*****************************@40tude.net...
On Thu, 15 Jan 2004 09:47:30 +0200, Crirus wrote:
the players are indeed childs of game.. was a TAB missing there
Map is a separate class only with data of the terrain
Players join to game not to map in my design

How to traverse up such a graph?


My only thought on that would be that each object would have a "parent"
property or perhaps a "ContainedBy" proprty that contains a reference to
the object that contains them. As each object is created, its parent
object could be set. I don't know how a heirarchy like this might affect
performance.

So a Unit could get the map data by using something like

Squad = Unit.Parent 'Get the squad the unit is in
Player = Squad.Parent 'Get the Player that owns the squad
Map = Player.Parent 'Get the map object for the player
Game = Map.Parent 'Get the game object for that map

There may be better ways, though

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.