ksquares
KSquaresGame Class Reference
#include <ksquaresgame.h>

Detailed Description
The game controller.Keeps charge of the game. Everything you'd expect really.
- Create one instance of this class which will last the whole time the program is running.
- In order to start a (new) game just call createGame() with the appropriate arguments.
- Once the game is started, play passes to the first player. takeTurnSig() will be emitted to allow you to chose how the go should be taken (AI controller or 'click' from a View).
- However the turn is taken, to make the move, the addLineToIndex() function must be called. This will emit the drawLine() signal to allow you to draw the line on the board with the correct colours.
- If the player completed a square, drawSquare() will then be emitted to allow you to draw the completed square with the correct colour.
- If the player gets another go, takeTurnSig() will be emitted again. If not, play will pass to the next player and takeTurnSig() will be emitted for them.
- If a player completes the scoreboard, gameOver() will be emitted with the full list of players to allow you to construct a score board.
- All variables will remain in the state they were at the end of the game until createGame() is called again.
Definition at line 44 of file ksquaresgame.h.
Public Slots | |
| void | addLineToIndex (int index) |
Signals | |
| void | takeTurnSig (KSquaresPlayer *) |
| void | gameOver (const QVector< KSquaresPlayer > &) |
| void | drawLine (int, QColor) |
| void | drawSquare (int, QColor) |
Public Member Functions | |
| KSquaresGame () | |
| ~KSquaresGame () | |
| void | createGame (const QVector< KSquaresPlayer > &startPlayers, int startWidth, int startHeight) |
| void | start () |
| void | stop () |
| int | currentPlayerId () const |
| KSquaresPlayer * | currentPlayer () |
| QList< int > | squares () const |
| QList< bool > | lines () const |
| int | boardWidth () const |
| int | boardHeight () const |
Protected Member Functions | |
| int | nextPlayer () |
| void | resetEverything () |
| void | tryEndGo () |
| void | checkForNewSquares () |
| void | playerSquareComplete (int index) |
Protected Attributes | |
| int | numOfPlayers |
| int | width |
| int | height |
| QList< int > | squareOwnerTable |
| QList< bool > | lineList |
| QVector< KSquaresPlayer > | players |
| int | i_currentPlayerId |
| bool | anotherGo |
| bool | gameInProgress |
Constructor & Destructor Documentation
| KSquaresGame::KSquaresGame | ( | ) |
| KSquaresGame::~KSquaresGame | ( | ) |
Definition at line 23 of file ksquaresgame.cpp.
Member Function Documentation
| void KSquaresGame::createGame | ( | const QVector< KSquaresPlayer > & | startPlayers, | |
| int | startWidth, | |||
| int | startHeight | |||
| ) |
Create a new game.
- Parameters:
-
startPlayers liat of the players in the game startWidth the width of the game board startHeight the height of the game board
Definition at line 29 of file ksquaresgame.cpp.
| void KSquaresGame::start | ( | ) | [inline] |
| void KSquaresGame::stop | ( | ) | [inline] |
| int KSquaresGame::currentPlayerId | ( | ) | const [inline] |
- Returns:
- the id of the current player.
0 >= id < number of players
Definition at line 72 of file ksquaresgame.h.
| KSquaresPlayer* KSquaresGame::currentPlayer | ( | ) | [inline] |
| QList<int> KSquaresGame::squares | ( | ) | const [inline] |
| QList<bool> KSquaresGame::lines | ( | ) | const [inline] |
| int KSquaresGame::boardWidth | ( | ) | const [inline] |
| int KSquaresGame::boardHeight | ( | ) | const [inline] |
| void KSquaresGame::addLineToIndex | ( | int | index | ) | [slot] |
| int KSquaresGame::nextPlayer | ( | ) | [protected] |
Moves play control to the next player, looping round when necessary.
- Returns:
- the Id of the player who's turn just started
Definition at line 55 of file ksquaresgame.cpp.
| void KSquaresGame::resetEverything | ( | ) | [protected] |
| void KSquaresGame::tryEndGo | ( | ) | [protected] |
A line was drawn, see if the player gets another go.
Definition at line 89 of file ksquaresgame.cpp.
| void KSquaresGame::checkForNewSquares | ( | ) | [protected] |
Scans the board to see if any new squares were completed.
Definition at line 139 of file ksquaresgame.cpp.
| void KSquaresGame::playerSquareComplete | ( | int | index | ) | [protected] |
A player completed a square.
Emits the lineDrawn() signal. Checks to see if the game is over.
- Parameters:
-
index the index of the square which was completed
Definition at line 66 of file ksquaresgame.cpp.
| void KSquaresGame::takeTurnSig | ( | KSquaresPlayer * | ) | [signal] |
A player's turn has started. This allows you to use AI/networking etc.
| void KSquaresGame::gameOver | ( | const QVector< KSquaresPlayer > & | ) | [signal] |
emitted when the game board is completed. Allows you to construct a scoreboard
| void KSquaresGame::drawLine | ( | int | , | |
| QColor | ||||
| ) | [signal] |
Emits the index and colour of the line.
| void KSquaresGame::drawSquare | ( | int | , | |
| QColor | ||||
| ) | [signal] |
Emits the index and colour of the square.
Member Data Documentation
int KSquaresGame::numOfPlayers [protected] |
int KSquaresGame::width [protected] |
int KSquaresGame::height [protected] |
QList<int> KSquaresGame::squareOwnerTable [protected] |
QList<bool> KSquaresGame::lineList [protected] |
QVector<KSquaresPlayer> KSquaresGame::players [protected] |
int KSquaresGame::i_currentPlayerId [protected] |
bool KSquaresGame::anotherGo [protected] |
bool KSquaresGame::gameInProgress [protected] |
The documentation for this class was generated from the following files:
KDE 4.0 API Reference