Planeshift
psminigameboard.h
Go to the documentation of this file.
1 /*
2 * psminigameboard.h
3 *
4 * Copyright (C) 2008 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __MINIGAMEBOARD_H
21 #define __MINIGAMEBOARD_H
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 
27 //=============================================================================
28 // Project Includes
29 //=============================================================================
30 #include "psstdint.h"
31 
32 //=============================================================================
33 // Local Includes
34 //=============================================================================
35 
36 class Client;
37 
41 #define GAMEBOARD_MIN_PLAYERS 1
42 #define GAMEBOARD_MAX_PLAYERS 2
43 #define GAMEBOARD_DEFAULT_PLAYERS 2
44 
49 {
53 };
55 {
59 };
61 {
64 };
66 {
69 };
71 {
72  ANY,
77 };
78 
84 {
91 };
92 
94 {
95  int col;
96  int row;
98  uint8_t specificTile;
99 };
100 
102 {
103  bool positionsAbsolute; // true=x,y coords absolute, false=coords relative to source tile
106  csArray<Endgame_TileSpec*> endgameTiles;
107 };
108 
109 /*********************************************************************************/
110 
117 {
118  friend class psMiniGameBoard;
119 
120 public:
121 
122  psMiniGameBoardDef(const uint8_t defCols, const uint8_t defRows,
123  const char* defLayout, const char* defPieces,
124  const uint8_t defPlayers, const int16_t options);
125 
127 
129  uint8_t GetCols() const
130  {
131  return cols;
132  }
133 
135  uint8_t GetRows() const
136  {
137  return rows;
138  }
139 
141  int GetLayoutSize() const
142  {
143  return layoutSize;
144  };
145 
147  void PackLayoutString(const char* layoutStr, uint8_t* packedLayout);
148 
150  uint8_t PackPiece(char pieceStr);
151 
153  uint16_t GetGameboardOptions(void)
154  {
155  return gameboardOptions;
156  };
157 
159  bool DetermineGameRules(csString rulesXMLstr, csString name);
160 
162  bool DetermineEndgameSpecs(csString endgameXMLstr, csString name);
163 
165  void ClearOutEndgames(void)
166  {
167  endgames.Empty();
168  };
169 
170 private:
172  int layoutSize;
173 
175  uint8_t* layout;
176 
178  uint8_t cols;
179 
181  uint8_t rows;
182 
184  uint8_t numPieces;
185 
187  uint8_t piecesSize;
188 
190  uint8_t* pieces;
191 
193  uint8_t numPlayers;
194 
196  int16_t gameboardOptions;
197 
199  Rule_PlayerTurn playerTurnRule;
200  Rule_MovePieceType movePieceTypeRule;
201  Rule_MoveablePieces moveablePiecesRule;
202  Rule_MovePiecesTo movePiecesToRule;
203  Rule_MoveDirection moveDirectionRule;
204  int moveDistanceRule;
205 
207  csArray<Endgame_Spec*> endgames;
208  bool EvaluateTileTypeStr(csString TileTypeStr, Endgame_TileType &tileType);
209 
210 };
211 
212 
219 {
220 public:
221 
222  psMiniGameBoard();
223 
224  ~psMiniGameBoard();
225 
227  void Setup(psMiniGameBoardDef* newGameDef, uint8_t* preparedLayout);
228 
230  uint8_t GetCols() const
231  {
232  return gameBoardDef->cols;
233  }
234 
236  uint8_t GetRows() const
237  {
238  return gameBoardDef->rows;
239  }
240 
242  uint8_t* GetLayout() const
243  {
244  return layout;
245  };
246 
248  uint8_t GetNumPieces() const
249  {
250  return gameBoardDef->numPieces;
251  }
252 
254  uint8_t GetPiecesSize() const
255  {
256  return gameBoardDef->piecesSize;
257  }
258 
260  uint8_t* GetPieces() const
261  {
262  return gameBoardDef->pieces;
263  }
264 
266  uint8_t Get(uint8_t col, uint8_t row) const;
267 
269  void Set(uint8_t col, uint8_t row, uint8_t state);
270 
272  uint8_t GetNumPlayers(void)
273  {
274  return gameBoardDef->numPlayers;
275  };
276 
279  {
280  return gameBoardDef->playerTurnRule;
281  };
283  {
284  return gameBoardDef->movePieceTypeRule;
285  };
287  {
288  return gameBoardDef->moveablePiecesRule;
289  };
291  {
292  return gameBoardDef->movePiecesToRule;
293  };
295  {
296  return gameBoardDef->moveDirectionRule;
297  };
299  {
300  return gameBoardDef->moveDistanceRule;
301  };
302 
304  bool DetermineEndgame(Endgame_TileType &winningPiece);
305 
306 private:
307 
309  Endgame_TileType EndgameWinner(uint8_t winningTileState);
310 
312  uint8_t* layout;
313 
315  psMiniGameBoardDef* gameBoardDef;
316 };
317 
318 #endif
319 
uint8_t GetRows() const
Returns the number of rows.
Endgame_TileType
structs & types used to specify endgames of minigames, to recognise specific patterns of played piece...
Endgame_TileType tile
Endgame_TileType sourceTile
Rule_MovePiecesTo GetMovePiecesToRule(void)
Rule_MoveablePieces
Rule_MoveDirection
Rule_PlayerTurn
Following enums define values to represent simple game rules.
Wrapper class for game board.
uint8_t * GetPieces() const
Returns the package list of available pieces.
uint8_t GetCols() const
Returns the number of columns.
uint8_t GetCols() const
Returns the number of columns.
Game board definition class.
Rule_MoveDirection GetMoveDirectionRule(void)
uint8_t * GetLayout() const
Returns the packed game board layout.
Rule_MovePieceType
uint8_t GetRows() const
Returns the number of rows.
Endgame_TileType winner
This class collects data of a netclient.
Definition: client.h:95
Rule_PlayerTurn GetPlayerTurnRule(void)
return Game rules
uint16_t GetGameboardOptions(void)
returns gameboard layout options
int GetLayoutSize() const
returns layout size
Rule_MovePiecesTo
int GetMoveDistanceRule(void)
Rule_MovePieceType GetMovePieceTypeRule(void)
void ClearOutEndgames(void)
clear endgame settings away
uint8_t GetNumPieces() const
Returns the number of available pieces.
uint8_t GetNumPlayers(void)
returns number of players
uint8_t GetPiecesSize() const
Returns the number of available pieces.
csArray< Endgame_TileSpec * > endgameTiles
Rule_MoveablePieces GetMoveablePiecesRule(void)