PDA

View Full Version : Checkers in Qt - ideas for board and pieces representation



Rampadow
2nd January 2012, 23:45
Hi all.

I'm working on a multiplayer checkers game in Qt and I wonder what board and pieces representation should I implement.

Currently, I have a main window class responsible for GUI and network connection. It contains an object of class Board (based on QGraphicsScene). Board class contains an array of 32 objects of class Square (based on QGraphicsItem) and an array of 24 objects of class Piece (based on QGraphicsItem). I thought to create access methods (to squares and pieces) in Board class and add needed members to square and piece classes (ident, pointer to occuping piece for square and color, type, pointer to occupied square for piece). In my idea piece should be responsible for checking for possible moves and making them etc.

Is that good idea? I wonder wheter I should bind game logic and graphical interface that much. Do you have any advices or other solutions to this problem? This is my first "serious" application and I'm confused a little. Thanks in advance for your help and sorry for my poor english.

Spitfire
4th January 2012, 15:59
Make the GUI to be your view.
View should have a bunch of elements that have methods related to their visual appearnce, ie move( MyGame::Left ), changeColor() but they don't have any business logic.

Then you should have a controller object that will use the view to reflect what's going on and will know what is where, what can be done etc.
This pattern is called MVC (in this case just VC).

That would be my approach.