Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a puzzle game with a 6 by 6 grid of storage tanks that are connected to up to 4 tanks adjacent to them via pipes. The gameplay is concerned with combining what's in a tank with an adjacent tank via the pipe than interconnects them.

Right now I store the tanks in a 6x6 array, vertical pipes in a 5x6 array, and horizontal pipes in a 6x5 array. Each tank has a reference to the object that contains both tanks and pipes and when a pipe needs to be animated filling with liquid, the selected tank just calls a method on the container object telling it to animate the pipes it is connected to (subtract 1 from row or column to find connected pipes).

This feels like the wrong way of doing it, as I've also considered just giving each tank references to the pipes connected to it to access directly.

share|improve this question
    
A picture speaks a thousand words. If you can provide a screenshot of the type of thing you're after, I think it would greatly help this question getting some more answers. –  Ray Dey Nov 20 '11 at 15:48

1 Answer 1

up vote 0 down vote accepted

You can easily replace your array architecture with an object-based approach where tanks have pointers to there adjacent pipes and the pipes know about their start and end object.

What you're doing here is modelling a graph. The tanks are the graphs nodes (vertices) and the pipes are the edges.

Of course you can also model a graph using an array. Usually you would use an adjacency matrix for that.

The appropriate structure really depends on your architecture and how you're accessing the data and what you're planning to do with it. The object based approach is closer to reality and might be easier to work with.

share|improve this answer
    
Giving pipes references to tanks and tanks references to pipes would be circular. Couldn't that cause problems later on? –  mars Nov 20 '11 at 7:16
    
Circular references aren't a problem if you know about them and code your structures in a way that handles/frees these references correctly. I don't know what language you use to write your game, but there are existing graph implementations for all mayor programming-languages if you don't want to write this yourself. –  bummzack Nov 20 '11 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.