views:

38

answers:

1

Hi

I am making a WPF soccer game using C#, and was wondering if it was possible to, say, put players in a class and when the ball hits them the same collision properties apply to all. And when you get the bounds for a bunch of objects, it gets the bounds for all in one sweep.

Anyway, is it possible to treat multiple, identical but separate objects as one? And how? Thx

+2  A: 

It depends on what you're trying to do. If they all want to react to the same event, you could attach event handlers for each of them. If you want to react the same way if any of them raises the same event, you could attach the same event handler to each of them.

If you just want to do the same thing to each item, normally a foreach loop would be fine.

You could apply the composite pattern too: create an interface which each item implements, and then a composite class which also implements the interface, delegating calls to each item in the collection it's responsible for.

If these ideas don't help, please give a concrete code example.

Jon Skeet
Cheers for the pointer man. 1 up. That looks like what I'm looking for.
NeoHaxxor