Planeshift

pawsgameboard.h

Go to the documentation of this file.
00001 /*
00002 * pawsgameboard.h - Author: Enar Vaikene
00003 *
00004 * Copyright (C) 2006 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __PAWSGAMEBOARD_H
00021 #define __PAWSGAMEBOARD_H
00022 
00023 #include "util/minigame.h"
00024 #include "net/messages.h"
00025 #include "paws/pawswidget.h"
00026 
00027 class pawsGameBoard;
00028 
00033 class pawsGameTile : public pawsWidget
00034 {
00035 
00036     public:
00037 
00038         pawsGameTile();
00039 
00040         ~pawsGameTile();
00041 
00043         void SetGameBoard(pawsGameBoard *gameBoard);
00044 
00046         void SetColumn(int8_t newColumn);
00047 
00049         int8_t GetColumn() const { return column; }
00050 
00052         void SetRow(int8_t newRow);
00053 
00055         int8_t GetRow() const { return row; }
00056 
00058         virtual bool OnMouseDown(int button, int modifiers, int x, int y);
00059 
00061         virtual bool OnDoubleClick(int button, int modifiers, int x, int y);
00062 
00064         virtual void Draw();
00065 
00067         uint8_t GetState() const { return state; }
00068 
00070         void SetState(uint8_t state);
00071 
00073         void RestoreState();
00074 
00075     protected:
00076 
00078         pawsGameBoard *board;
00079 
00081         int8_t column;
00082 
00084         int8_t row;
00085 
00087         uint8_t state;
00088 
00090         uint8_t oldState;
00091 
00093         csRef<iPawsImage> image;
00094 
00095 };
00096 
00102 class pawsGameBoard : public pawsWidget, public psClientNetSubscriber
00103 {
00104     public:
00105 
00106         pawsGameBoard();
00107 
00108         ~pawsGameBoard();
00109 
00111         virtual void HandleMessage(MsgEntry *message);
00112 
00114         virtual bool PostSetup();
00115 
00117         virtual void Hide();
00118 
00120         void CleanBoard();
00121 
00123         void StartGame();
00124 
00126         void SetupBoard(psMGBoardMessage &msg);
00127 
00129         void UpdateBoard(psMGBoardMessage &msg);
00130 
00132         uint32_t GetGameID() const { return gameID; }
00133 
00135         uint16_t GetGameOptions() const { return gameOptions; }
00136 
00138         void SetGameOptions(uint16_t newOptions);
00139 
00141         int8_t GetCols() const { return cols; }
00142 
00144         int8_t GetRows() const { return  rows; }
00145 
00147         bool IsDragging() const { return dragging; }
00148 
00150         void StartDragging(pawsGameTile *tile);
00151 
00153         void DropPiece(pawsGameTile *tile = 0);
00154 
00156         void UpdatePiece(pawsGameTile *tile);
00157 
00159         uint8_t WhitePiecesList(size_t idx) const
00160         {
00161             if (whitePieces.GetSize() > 0)
00162                 return whitePieces.Get(idx);
00163             else
00164                 return psMiniGame::WHITE_1;
00165         }
00166 
00168         uint8_t BlackPiecesList(size_t idx) const
00169         {
00170             if (blackPieces.GetSize() > 0)
00171                 return blackPieces.Get(idx);
00172             else
00173                 return psMiniGame::BLACK_1;
00174         }
00175 
00177         size_t WhitePiecesCount() const
00178         {
00179             if (whitePieces.GetSize() > 0)
00180                 return whitePieces.GetSize();
00181             else
00182                 return 1;
00183         }
00184 
00186         size_t BlackPiecesCount() const
00187         {
00188             if (blackPieces.GetSize() > 0)
00189                 return blackPieces.GetSize();
00190             else
00191                 return 1;
00192         }
00193 
00195         uint8_t NextPiece(uint8_t current) const;
00196 
00198         const csString PieceArtName(uint8_t piece) const;
00199 
00200     private:
00202         csArray<pawsGameTile *> tiles;
00203 
00205         uint8_t currentCounter;
00206 
00208         bool counterSet;
00209 
00211         uint32_t gameID;
00212 
00214         uint16_t gameOptions;
00215 
00217         int8_t cols;
00218 
00220         int8_t rows;
00221 
00223         bool dragging;
00224 
00226         pawsGameTile *draggingPiece;
00227 
00229         csHash<csString, int> pieceArt;
00230 
00232         csArray<int> whitePieces;
00233 
00235         csArray<int> blackPieces;
00236 
00237 };
00238 
00239 CREATE_PAWS_FACTORY(pawsGameBoard);
00240 CREATE_PAWS_FACTORY(pawsGameTile);
00241 
00242 #endif