ksquares
#include <ksquaresgame.h>
Public Slots | |
void | addLineToIndex (int index) |
Signals | |
void | drawLine (int, QColor) |
void | drawSquare (int, QColor) |
void | gameOver (const QVector< KSquaresPlayer > &) |
void | highlightMove (int) |
void | takeTurnSig (KSquaresPlayer *) |
Public Member Functions | |
KSquaresGame () | |
~KSquaresGame () | |
int | boardHeight () const |
int | boardWidth () const |
void | createGame (const QVector< KSquaresPlayer > &startPlayers, int startWidth, int startHeight) |
KSquaresPlayer * | currentPlayer () |
int | currentPlayerId () const |
QList< bool > | lines () const |
QList< int > | squares () const |
void | start () |
void | stop () |
void | switchPlayer () |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QObject (QObject *parent, const char *name) | |
virtual | ~QObject () |
bool | blockSignals (bool block) |
QObject * | child (const char *objName, const char *inheritsClass, bool recursiveSearch) const |
const QObjectList & | children () const |
const char * | className () const |
bool | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const QObject *receiver, const char *method) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QByteArray > | dynamicPropertyNames () const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name) const |
QList< T > | findChildren (const QRegExp ®Exp) const |
QList< T > | findChildren (const QString &name) const |
bool | inherits (const char *className) const |
void | insertChild (QObject *object) |
void | installEventFilter (QObject *filterObj) |
bool | isA (const char *className) const |
bool | isWidgetType () const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
const char * | name () const |
const char * | name (const char *defaultName) const |
QString | objectName () const |
QObject * | parent () const |
QVariant | property (const char *name) const |
void | removeChild (QObject *object) |
void | removeEventFilter (QObject *obj) |
void | setName (const char *name) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval) |
QThread * | thread () const |
Protected Member Functions | |
void | checkForNewSquares () |
int | nextPlayer () |
void | playerSquareComplete (int index) |
void | resetEverything () |
void | tryEndGo () |
Protected Member Functions inherited from QObject | |
bool | checkConnectArgs (const char *signal, const QObject *object, const char *method) |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const char *signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const char *signal) |
int | receivers (const char *signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Protected Attributes | |
bool | anotherGo |
bool | gameInProgress |
int | height |
int | i_currentPlayerId |
int | lastLine |
QList< bool > | lineList |
int | numOfPlayers |
QVector< KSquaresPlayer > | players |
QList< int > | squareOwnerTable |
int | width |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
Static Protected Member Functions inherited from QObject | |
QByteArray | normalizeSignalSlot (const char *signalSlot) |
Properties inherited from QObject | |
objectName | |
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.
Constructor & Destructor Documentation
KSquaresGame::KSquaresGame | ( | ) |
Constructor.
Definition at line 17 of file ksquaresgame.cpp.
KSquaresGame::~KSquaresGame | ( | ) |
Definition at line 23 of file ksquaresgame.cpp.
Member Function Documentation
|
slot |
- Parameters
-
index the index of the line to add
Definition at line 134 of file ksquaresgame.cpp.
|
inline |
- Returns
- the height of the game board
Definition at line 98 of file ksquaresgame.h.
|
inline |
- Returns
- the width of the game board
Definition at line 94 of file ksquaresgame.h.
|
protected |
Scans the board to see if any new squares were completed.
Definition at line 151 of file ksquaresgame.cpp.
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.
|
inline |
- Returns
- the current player
Definition at line 80 of file ksquaresgame.h.
|
inline |
- Returns
- the id of the current player. 0 >= id < number of players
Definition at line 76 of file ksquaresgame.h.
|
signal |
Emits the index and colour of the line.
|
signal |
Emits the index and colour of the square.
|
signal |
emitted when the game board is completed. Allows you to construct a scoreboard
|
signal |
Emitted when the last move in a series is played by the AI.
|
inline |
- Returns
- the list of lines
Definition at line 90 of file ksquaresgame.h.
|
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 61 of file ksquaresgame.cpp.
|
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 72 of file ksquaresgame.cpp.
|
protected |
Sets lots of things to zero, clears lists etc.
Definition at line 119 of file ksquaresgame.cpp.
|
inline |
- Returns
- the table of currently owned squares
Definition at line 86 of file ksquaresgame.h.
|
inline |
Starts the game.
Definition at line 64 of file ksquaresgame.h.
|
inline |
Stops the game.
Definition at line 68 of file ksquaresgame.h.
void KSquaresGame::switchPlayer | ( | ) |
Externally determined player switch, for network game.
Definition at line 55 of file ksquaresgame.cpp.
|
signal |
A player's turn has started. This allows you to use AI/networking etc.
|
protected |
A line was drawn, see if the player gets another go.
Definition at line 95 of file ksquaresgame.cpp.
Member Data Documentation
|
protected |
Should the current player have another go.
Definition at line 147 of file ksquaresgame.h.
|
protected |
is there currently a game in progress
Definition at line 149 of file ksquaresgame.h.
|
protected |
Height of the game board.
Definition at line 133 of file ksquaresgame.h.
|
protected |
Id of the current player.
Definition at line 145 of file ksquaresgame.h.
|
protected |
last line added
Definition at line 151 of file ksquaresgame.h.
|
protected |
List of the lines and whether they're drawn.
Definition at line 137 of file ksquaresgame.h.
|
protected |
Number of players in this game.
Definition at line 129 of file ksquaresgame.h.
|
protected |
List of all the players in the game.
Definition at line 141 of file ksquaresgame.h.
|
protected |
List of the squares and their owners.
Definition at line 135 of file ksquaresgame.h.
|
protected |
Width of the game board.
Definition at line 131 of file ksquaresgame.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.