Creating the GUI for a Monopoly game
Hi everybody! I am trying to develop a Monopoly game in Qt (with some kde stuff), but I got stuck when I had to think about how to create the graphic interface. I read something about QGraphics Framework, but I have no idea how to set up a solution and use it.
How can I draw the board using QGraphicsScene and QGraphicsView?
Thanks in advance!
and QML is not an option is it?
simple way to approach this is take a look at the QGraphicsView framework documentation in the assistant. also there are very nice demos and examples with source code already available with Qt sdk.
you have a scene that you set to the graphics view.
you create your graphic items (various types) and add them to the scene.
you can apply effects and also move these graphic items very easily within the scene.
you can set the z order for these items and use them as layers too ...
The GraphicsView framework does lend itself quite well for this kind of application, I think. As chetankjain pointed out, you'll need to dive into the documentation to learn how to use it. It really isn't all that difficult. The basic architecture is like this:
A QGraphicsItem (or, more likely, one of its many subclasses) is an item that you can put on a QGraphicsScene. The scene acts as the canvas to put your rectangles, texts, etc. on. A QGraphicsView provides a view onto a QGraphicsScene. You might have more than one view on the same scene, just like you can have multiple item views display the same data model at the same time in different views. QGraphicsItems can also have parent-child relationships. That is: you can create hierarchy's of items belonging together. Note that unlike the situation in the QWidget world, this does not mean that the child item is somehow contained or clipped to the parent item. This allows you to make logical groupings of your items. In your case, you may want to create an item for each position on the monopoly board, with a child item for the colored bar where the houses and hotels will appear, and a child item for the text that indicates the street and city name. You can then position this item as one unit, and you can create many of these units to represent each position on the board.
Thank you very much for your replies. I hope there are methods that allow to arrange the positions side by side. Another discouraging thing is that I have to move pawns along the board, and retrieve the current "cell" after a roll... I'll give a look at the documentation, thank you!
Positioning items next to onanother is not that hard, and recently got even easier. Take a look at QGraphicsAnchorLayout. This will make it quite easy to position the items relative to each other, including putting them in the configuration you need for a monopoly board.
Moving pawns is not all that hard, and you can even animate these movements nicely.
Ok, thank you for your help, I'll start reading the docs and working on!
do post back your monopoly in showcase, i'd like to download it ;)