Planeshift
pawsgameboard.h
Go to the documentation of this file.
1 /*
2 * pawsgameboard.h - Author: Enar Vaikene
3 *
4 * Copyright (C) 2006 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 __PAWSGAMEBOARD_H
21 #define __PAWSGAMEBOARD_H
22 
23 #include "util/minigame.h"
24 #include "net/messages.h"
25 #include "paws/pawswidget.h"
26 
27 class pawsGameBoard;
28 
33 class pawsGameTile : public pawsWidget
34 {
35 
36  public:
37 
38  pawsGameTile();
39 
40  ~pawsGameTile();
41 
43  void SetGameBoard(pawsGameBoard *gameBoard);
44 
46  void SetColumn(int8_t newColumn);
47 
49  int8_t GetColumn() const { return column; }
50 
52  void SetRow(int8_t newRow);
53 
55  int8_t GetRow() const { return row; }
56 
58  virtual bool OnMouseDown(int button, int modifiers, int x, int y);
59 
61  virtual bool OnDoubleClick(int button, int modifiers, int x, int y);
62 
64  virtual void Draw();
65 
67  uint8_t GetState() const { return state; }
68 
70  void SetState(uint8_t state);
71 
73  void RestoreState();
74 
75  protected:
76 
79 
81  int8_t column;
82 
84  int8_t row;
85 
87  uint8_t state;
88 
90  uint8_t oldState;
91 
93  csRef<iPawsImage> image;
94 
95 };
96 
103 {
104  public:
105 
106  pawsGameBoard();
107 
108  ~pawsGameBoard();
109 
111  virtual void HandleMessage(MsgEntry *message);
112 
114  virtual bool PostSetup();
115 
117  virtual void Hide();
118 
120  void CleanBoard();
121 
123  void StartGame();
124 
126  void SetupBoard(psMGBoardMessage &msg);
127 
129  void UpdateBoard(psMGBoardMessage &msg);
130 
132  uint32_t GetGameID() const { return gameID; }
133 
135  uint16_t GetGameOptions() const { return gameOptions; }
136 
138  void SetGameOptions(uint16_t newOptions);
139 
141  int8_t GetCols() const { return cols; }
142 
144  int8_t GetRows() const { return rows; }
145 
147  bool IsDragging() const { return dragging; }
148 
150  void StartDragging(pawsGameTile *tile);
151 
153  void DropPiece(pawsGameTile *tile = 0);
154 
156  void UpdatePiece(pawsGameTile *tile);
157 
159  uint8_t WhitePiecesList(size_t idx) const
160  {
161  if (whitePieces.GetSize() > 0)
162  return whitePieces.Get(idx);
163  else
164  return psMiniGame::WHITE_1;
165  }
166 
168  uint8_t BlackPiecesList(size_t idx) const
169  {
170  if (blackPieces.GetSize() > 0)
171  return blackPieces.Get(idx);
172  else
173  return psMiniGame::BLACK_1;
174  }
175 
177  size_t WhitePiecesCount() const
178  {
179  if (whitePieces.GetSize() > 0)
180  return whitePieces.GetSize();
181  else
182  return 1;
183  }
184 
186  size_t BlackPiecesCount() const
187  {
188  if (blackPieces.GetSize() > 0)
189  return blackPieces.GetSize();
190  else
191  return 1;
192  }
193 
195  uint8_t NextPiece(uint8_t current) const;
196 
198  const csString PieceArtName(uint8_t piece) const;
199 
200  private:
202  csArray<pawsGameTile *> tiles;
203 
205  uint8_t currentCounter;
206 
208  bool counterSet;
209 
211  uint32_t gameID;
212 
214  uint16_t gameOptions;
215 
217  int8_t cols;
218 
220  int8_t rows;
221 
223  bool dragging;
224 
226  pawsGameTile *draggingPiece;
227 
229  csHash<csString, int> pieceArt;
230 
232  csArray<int> whitePieces;
233 
235  csArray<int> blackPieces;
236 
237 };
238 
241 
242 #endif
int8_t GetColumn() const
Returns the column number for this game tile.
Definition: pawsgameboard.h:49
void SetGameBoard(pawsGameBoard *gameBoard)
Sets the game board field.
Message from the server to setup/update the minigame board on the client side.
Definition: messages.h:5631
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
uint8_t state
The current game tile state.
Definition: pawsgameboard.h:87
void SetState(uint8_t state)
Sets the game tile state.
void RestoreState()
Restores the previous game tile state.
Game tile class.
Definition: pawsgameboard.h:33
void SetRow(int8_t newRow)
Sets the row number for this game tile.
White regular game piece.
Definition: minigame.h:58
int8_t GetRows() const
Returns the number of rows.
virtual bool PostSetup()
This is called after the widget and all of it&#39;s children have been created.
Definition: pawswidget.h:709
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
void SetColumn(int8_t newColumn)
Sets the column number for this game tile.
uint32_t GetGameID() const
Returns the game ID value.
int8_t GetCols() const
Returns the number of columns.
CREATE_PAWS_FACTORY(pawsGameBoard)
int8_t GetRow() const
Returns the row number for this game tile.
Definition: pawsgameboard.h:55
virtual void Draw()
Draws the game tile.
uint8_t GetState() const
Return the game tile state.
Definition: pawsgameboard.h:67
size_t BlackPiecesCount() const
Number of available black pieces.
uint8_t WhitePiecesList(size_t idx) const
List of available white pieces.
size_t WhitePiecesCount() const
Number of available white pieces.
csRef< iPawsImage > image
The game piece image.
Definition: pawsgameboard.h:93
uint16_t GetGameOptions() const
Returns game options.
int8_t row
The row number on the game board.
Definition: pawsgameboard.h:84
uint8_t BlackPiecesList(size_t idx) const
List of available black pieces.
The game window class.
bool IsDragging() const
Returns true if a game piece is being dragged.
virtual bool OnMouseDown(int button, int modifiers, int x, int y)
Mouse event.
uint8_t oldState
The previous game tile state.
Definition: pawsgameboard.h:90
pawsGameBoard * board
The game board.
Definition: pawsgameboard.h:78
Black regular game piece.
Definition: minigame.h:66
int8_t column
The column number on the game board.
Definition: pawsgameboard.h:81
virtual void Hide()
Makes widget invisible and removes focus if widget has current focus.
virtual bool OnDoubleClick(int button, int modifiers, int x, int y)
Double-click event.