• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

ksquares

  • sources
  • kde-4.14
  • kdegames
  • ksquares
  • src
ksquaresgame.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Matthew Williams <matt@milliams.com> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  ***************************************************************************/
9 
10 #ifndef KSQUARESGAME_H
11 #define KSQUARESGAME_H
12 
13 #include <QObject>
14 #include <QVector>
15 
16 #include "ksquaresplayer.h"
17 
18 class QColor;
19 
44 class KSquaresGame : public QObject
45 {
46  Q_OBJECT
47 
48  public:
50  KSquaresGame();
51  ~KSquaresGame();
52 
60  void createGame(const QVector<KSquaresPlayer> &startPlayers, int startWidth, int startHeight);
64  void start() {gameInProgress = true;}
68  void stop() {gameInProgress = false;}
72  void switchPlayer();
76  int currentPlayerId() const {return i_currentPlayerId;}
80  KSquaresPlayer* currentPlayer() {return &players[currentPlayerId()];}
81 
82  //getters
86  QList<int> squares() const {return squareOwnerTable;}
90  QList<bool> lines() const {return lineList;}
94  int boardWidth() const {return width;}
98  int boardHeight() const {return height;}
99 
100  public Q_SLOTS:
104  void addLineToIndex(int index);
105 
106  protected:
112  int nextPlayer();
114  void resetEverything();
115 
117  void tryEndGo();
119  void checkForNewSquares();
125  void playerSquareComplete(int index);
126 
127  // Static throughout each game
129  int numOfPlayers;
131  int width;
133  int height;
135  QList<int> squareOwnerTable;
137  QList<bool> lineList;
138 
139  // Updated as the game progresses
141  QVector<KSquaresPlayer> players;
142 
143  // Probably changes every go
145  int i_currentPlayerId;
147  bool anotherGo;
149  bool gameInProgress;
151  int lastLine;
152  signals:
154  void takeTurnSig(KSquaresPlayer*); //emit the new curent player
156  void gameOver(const QVector<KSquaresPlayer> &); //for scoreboard purposes
158  void drawLine(int,QColor); //int == lineList index
160  void drawSquare(int,QColor); //int == squareOwnerTable index
162  void highlightMove(int);
163 };
164 
165 #endif // KSQUARESGAME_H
KSquaresPlayer
Player class for KSquares.
Definition: ksquaresplayer.h:23
KSquaresGame::height
int height
Height of the game board.
Definition: ksquaresgame.h:133
KSquaresGame
The game controller.
Definition: ksquaresgame.h:44
KSquaresGame::numOfPlayers
int numOfPlayers
Number of players in this game.
Definition: ksquaresgame.h:129
KSquaresGame::createGame
void createGame(const QVector< KSquaresPlayer > &startPlayers, int startWidth, int startHeight)
Create a new game.
Definition: ksquaresgame.cpp:29
KSquaresGame::tryEndGo
void tryEndGo()
A line was drawn, see if the player gets another go.
Definition: ksquaresgame.cpp:95
KSquaresGame::KSquaresGame
KSquaresGame()
Constructor.
Definition: ksquaresgame.cpp:17
KSquaresGame::players
QVector< KSquaresPlayer > players
List of all the players in the game.
Definition: ksquaresgame.h:141
KSquaresGame::lastLine
int lastLine
last line added
Definition: ksquaresgame.h:151
KSquaresGame::lines
QList< bool > lines() const
Definition: ksquaresgame.h:90
KSquaresGame::gameOver
void gameOver(const QVector< KSquaresPlayer > &)
emitted when the game board is completed. Allows you to construct a scoreboard
KSquaresGame::start
void start()
Starts the game.
Definition: ksquaresgame.h:64
KSquaresGame::resetEverything
void resetEverything()
Sets lots of things to zero, clears lists etc.
Definition: ksquaresgame.cpp:119
KSquaresGame::gameInProgress
bool gameInProgress
is there currently a game in progress
Definition: ksquaresgame.h:149
KSquaresGame::addLineToIndex
void addLineToIndex(int index)
Definition: ksquaresgame.cpp:134
KSquaresGame::stop
void stop()
Stops the game.
Definition: ksquaresgame.h:68
QObject
KSquaresGame::takeTurnSig
void takeTurnSig(KSquaresPlayer *)
A player's turn has started. This allows you to use AI/networking etc.
KSquaresGame::boardHeight
int boardHeight() const
Definition: ksquaresgame.h:98
KSquaresGame::squareOwnerTable
QList< int > squareOwnerTable
List of the squares and their owners.
Definition: ksquaresgame.h:135
KSquaresGame::squares
QList< int > squares() const
Definition: ksquaresgame.h:86
QList< int >
QColor
KSquaresGame::i_currentPlayerId
int i_currentPlayerId
Id of the current player.
Definition: ksquaresgame.h:145
KSquaresGame::highlightMove
void highlightMove(int)
Emitted when the last move in a series is played by the AI.
KSquaresGame::nextPlayer
int nextPlayer()
Moves play control to the next player, looping round when necessary.
Definition: ksquaresgame.cpp:61
KSquaresGame::~KSquaresGame
~KSquaresGame()
Definition: ksquaresgame.cpp:23
QVector< KSquaresPlayer >
KSquaresGame::currentPlayer
KSquaresPlayer * currentPlayer()
Definition: ksquaresgame.h:80
KSquaresGame::playerSquareComplete
void playerSquareComplete(int index)
A player completed a square.
Definition: ksquaresgame.cpp:72
KSquaresGame::switchPlayer
void switchPlayer()
Externally determined player switch, for network game.
Definition: ksquaresgame.cpp:55
KSquaresGame::currentPlayerId
int currentPlayerId() const
Definition: ksquaresgame.h:76
KSquaresGame::drawSquare
void drawSquare(int, QColor)
Emits the index and colour of the square.
KSquaresGame::drawLine
void drawLine(int, QColor)
Emits the index and colour of the line.
KSquaresGame::anotherGo
bool anotherGo
Should the current player have another go.
Definition: ksquaresgame.h:147
KSquaresGame::checkForNewSquares
void checkForNewSquares()
Scans the board to see if any new squares were completed.
Definition: ksquaresgame.cpp:151
KSquaresGame::lineList
QList< bool > lineList
List of the lines and whether they're drawn.
Definition: ksquaresgame.h:137
KSquaresGame::width
int width
Width of the game board.
Definition: ksquaresgame.h:131
KSquaresGame::boardWidth
int boardWidth() const
Definition: ksquaresgame.h:94
ksquaresplayer.h
This file is part of the KDE documentation.
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.

ksquares

Skip menu "ksquares"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal