I’m doing some OO Analysis to work out the relationships between game components so I can design the classes. I’ll end up in C#.
Requirements
My game will include:
Pieces: Blocks, Cards, Counters
Places: Grids, Stacks
Placement of pieces possible:
- Blocks can be placed on grids (Need grid, x,y)
- Cards can be placed on stacks (Need stack, position)
- Counters can be placed on grids (Need grid, x, y)
- Counters can also be placed on top of stacks (Need stack, position)
Analysis
- Piece as either an interface(IPiece) or an abstract class(Piece). (which is best?)
- Block, Card & Counter as implementations of IPiece or subclasses of Piece.
- Place as an interface(IPlace) or an abstract class(Place). (which is best?)
- Grid & Stack as implementations of IPlace or subclasses of Place.
Then I get confused...
Every Piece HAS-A Place so there’s a relationship there. It's a one-to-one relationship as every piece must have one and only one place.
But how do I ensure that Blocks can only go on grids, Cards only on stacks and Counters on either?
Thanks in advance for any help.