Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pool game - Which object should i use to store objects? (C#)


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
5 replies to this topic

#1 Lysergide   Members   -  Reputation: 675

Like
0Likes
Like

Posted 22 August 2008 - 11:19 PM

Hello All! I'm currently working on a pool game using the XNA framework. I have a BallManager object that handles all the balls on the table. Each ball is an object, and i'd like the BallManager to keep some sort of list to handle all these objects. My concerns are : a. This list should be dynamic, meaning that balls that are no longer available will be removed from the list. b. I'd like to keep some sort of indices to each position in the list, so i could perform something like: checkCollision(i, j) where (i,j) are indices in my ball list. Which type can i use to perform this? or is there any easier way u can think of ? Thanks, Lior.

Sponsor:

#2 Drigovas   Members   -  Reputation: 508

Like
0Likes
Like

Posted 23 August 2008 - 12:21 AM

Quote:
a. This list should be dynamic, meaning that balls that are no longer available will be removed from the list.

b. I'd like to keep some sort of indices to each position in the list, so i could perform something like: checkCollision(i, j) where (i,j) are indices in my ball list.
I feel like I'm almost being sarcastic for even bringing this up, but is there any reason why a 'list' [system.collections.generic.list<ball>] is insufficient?

#3 Lysergide   Members   -  Reputation: 675

Like
0Likes
Like

Posted 23 August 2008 - 12:26 AM

I don't know all the types of C#, i've been looking around MSDN but couldn't find what i was looking for ... :(

Only now i've seen this particular class.. thanks!

p.s u can hold the sarcasm until i reach an intermediate level.. it's not fair making fun of beginners ! :)

Lior.

#4 i_luv_cplusplus   Members   -  Reputation: 250

Like
0Likes
Like

Posted 23 August 2008 - 01:14 AM

Quote:
Original post by Liort
it's not fair making fun of beginners ! :)
Lior.

next time post in For Beginners forum :)



#5 warthog518   Members   -  Reputation: 122

Like
0Likes
Like

Posted 23 August 2008 - 08:38 AM

I reccomend you use a hashtable :)
(you can index with strings)
in flash you would do this:
_root["Ball"+i.toString()].doActions();

with a hastable you can do this:

HashTable listOfBalls;

foreach(object i in listOfBalls)
{
((Ball)i).doActions();
}

:) hope that helps

#6 Nik02   Crossbones+   -  Reputation: 2727

Like
0Likes
Like

Posted 23 August 2008 - 08:49 AM

In a pool game, there is no (immediately obvious) reason to use strings when looking up the balls, since each ball excluding cue ball has its associated integer value anyway. Cue ball will go nicely to index 0 [smile]

Furthermore, Generic.List also supports foreach as it implements IEnumerable.




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