I created a simple console game Scrabble using Python. I tried to encapsulate the game model from I / O as much as possible, that is, I created several classes to describe the game with my rules and current state. I basically came up with these classes:
LetterSet : describe the tiles in the game (score, total, etc.).Board : introducing the board with its tiles and auxiliary functionsPlayer : a virtual class for a subclass of real classes such as Human or Bot, got one play() method, which should return the movement of players.Game : Well ...
Everything works fine using a simple linear and synchronous stream with my console application.
But it turns out that it is not so easy to transfer this concept to Qt. I created all the necessary widgets, such as the Dragable board, general visual elements that describe the state of the game, and simple buttons, such as "Pass", "Continue", "Exchange".
The problem is that I'm not sure how to handle the play() method, which can use the Qt interface that I created to generate the actual move. This is not a problem for Bot though, which is simply looking for movement without any interaction.
My current idea is to create a local event loop described here and wait for the buttons to be pressed in my play() method defined in Human(Bot) . This is pretty ugly, so I'm wondering if there is a better way to do this.
I would like the main logic to be the same, for example, the Player class maintains the play() method, which generates a move and returns it. Thus, it should be possible to create any type of Player , for example, network players or bots. This is a synchronous way to do this. It doesn’t work very well with Qt based on signals / slots in a way to do things. Hope someone has a clear idea to solve my problem.
Summarized: How to generate a Player move inside its play() method and return it as a simple call to move = player.play(game) ?
Edit: Snapshot to understand what I'm talking about: snapshot http://reaktor42.de/~b52/shots/2011-06-26-235749_972x729_scrot.png
Edit2: This is quite old, and I successfully completed the task two years ago. However, I thought it might be useful to others if I post the results via github .
Thanks in advance, Oli