How to implement a board game with a custom board and pieces
-
Hi all,
I'm a Qt beginner and a bit overwhelmed by the size of the API. I'm looking to the following using C++ only, without QML or the WYSIWYG editor.
I'm looking to implement a board game with two colors (like chess) but where, unlike chess, players have to put the pieces on the board themselves before the game starts.
I'm wondering where I should look to:
-
Create a board with alternate colors and which could be resized if the window is resized. I was thinking about using a Widget but I'm not sure how to make that resizable, should it rather be a table view?
-
Create interactive pieces that can be either clicked on or drag-n-drop'ed to a new place on the board. This is definitely widget territory as far as I understand.
-
Color my pieces and display their values: each piece has a color and a value that should be displayed, it signifies how "strong" a piece is. I'm lost as to how I can color those items and display a value on top of the color.
The game logic is already implemented, it is called "Stratego" but I'm a bit lost as to how where I should look to implement the board, the pieces and not make insane design decisions.
Thanks
-
-
Game is 3D or 2D?
if 2D, you can design your board in QML with Canves.
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API -
It's a 2D game and I'm to use C++, not QML.
-
@NullFunction you can use QPainter class.
https://doc.qt.io/qt-5/qpainter.html#details -
@NullFunction
For the board, have a look at QGraphicsView and QGraphicsScene classes. -
I don't know the game but it looks like a grid so you probably can use the model/view framework for that (this is an example of implementation of chess that another user asked help with, you might use that as a starting example).
If you want something half-decent looking, however, use a proper game engine like Godot
-
@mpergand Thanks for the advice, is there any notable difference between the two? From the docs, it seems they do similar things but were introduced at different times, or at least in different parts of the API, is my understanding correct?
-
@NullFunction said in How to implement a board game with a custom board and pieces:
is there any notable difference between the two?
No, they are the 2 main pieces of the graphical framework, they do different things: https://doc.qt.io/qt-6/graphicsview.html
-
@VRonin Thank you, I'm not allowed to use a game engine, it it were up to me, I probably wouldn't be using Qt to make a game.
I'll probably use the M/V framework but the docs are somewhat confusing to me; different parts of the API are presented in different examples but there doesn't seem to be an overarching logic to the how and why of the examples.