
Originally Posted by
OriginalCopy
it is just about the graphical representation, the piece (the qobject you are proposing) itself will take care of the logic and of updating this "pawn" within the manager
It should work the other way round. The manager knows the logic of the game, it can delegate some of its resposibility to another object (which can happen to be the visual item drawn on the board but it doesn't have to be) but still the manager is in control of everything. If we continue with the chess parallel - if you want to add a new type of piece to the game then of course the logic of the piece can be tied to the component implementing the looks of the piece but it is still the game engine that asks a particular piece for possible destinations, determines the legality of each of them in the current game state and finally asks the piece to make the move. If you decentralize the logic (as if I correctly understand that that's what you propose) then you have dozens of places that you have to coordinate, dozens of places where something can go wrong, etc. Even if we consider your approach as a sort of an "agent-like" solution then there still has to be an agent controlling the game logic and the agent would be the manager.
In general through QGraphicsLayoutItem API.
QGraphicsWidget *w = new QGraphicsWidget;
QGraphicsGridLayout *l1 = new QGraphicsGridLayout;
w->setLayout(l1);
QGraphicsGridLayout *l2 = new QGraphicsGridLayout;
l1->addItem(l2, 0, 0);
// ...
QGraphicsWidget *w2 = new QGraphicsWidget;
QGraphicsGridLayout *l21 = new QGraphicsGridLayout;
w2->setLayout(l21);
QGraphicsGridLayout *l22 = new QGraphicsGridLayout;
l21->addItem(l22, 0, 0);
// ...
QGraphicsWidget *w = new QGraphicsWidget;
QGraphicsGridLayout *l1 = new QGraphicsGridLayout;
w->setLayout(l1);
QGraphicsGridLayout *l2 = new QGraphicsGridLayout;
l1->addItem(l2, 0, 0);
// ...
QGraphicsWidget *w2 = new QGraphicsWidget;
QGraphicsGridLayout *l21 = new QGraphicsGridLayout;
w2->setLayout(l21);
QGraphicsGridLayout *l22 = new QGraphicsGridLayout;
l21->addItem(l22, 0, 0);
// ...
To copy to clipboard, switch view to plain text mode
Bookmarks