00001 /***************************************************************************** 00002 * Copyright (C) 2004-2005 Eliot 00003 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 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 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 *****************************************************************************/ 00019 00020 #ifndef _PLAYER_H_ 00021 #define _PLAYER_H_ 00022 00023 #include <vector> 00024 #include <string> 00025 #include "pldrack.h" 00026 #include "history.h" 00027 00028 class Turn; 00029 00030 00031 /** 00032 * This class is the parent class for all the players involved in a game. 00033 * It defines the common methods to update the rack, score, etc... 00034 */ 00035 class Player 00036 { 00037 public: 00038 Player(int iId); 00039 virtual ~Player(); 00040 00041 // Pseudo RTTI 00042 virtual bool isHuman() const = 0; 00043 00044 /************************** 00045 * General getters 00046 **************************/ 00047 // Get the (possibly incomplete) rack of the player 00048 const PlayedRack & getCurrentRack() const; 00049 // Get the previous rack 00050 const PlayedRack & getLastRack() const; 00051 // Get the previous round (corresponding to the previous rack...) 00052 const Round & getLastRound() const; 00053 00054 void setCurrentRack(const PlayedRack &iPld); 00055 00056 const History& getHistory() const { return m_history; } 00057 /// Remove last turn 00058 void removeLastTurn(); 00059 00060 /************************** 00061 * Acessors for the score of the player 00062 **************************/ 00063 // Add (or remove, if iPoints is negative) points to the score 00064 // of the player 00065 void addPoints(int iPoints) { m_score += iPoints; } 00066 int getPoints() const { return m_score; } 00067 00068 // Update the player "history", with the given round. 00069 // A new rack is created with the remaining letters 00070 void endTurn(const Round &iRound, int iTurn); 00071 00072 const string toString() const; 00073 00074 private: 00075 /// ID of the player 00076 int m_id; 00077 00078 /// Score of the player 00079 int m_score; 00080 00081 /// History of the racks and rounds for the player 00082 History m_history; 00083 }; 00084 00085 00086 /** 00087 * Human player. 00088 */ 00089 class HumanPlayer: public Player 00090 { 00091 public: 00092 HumanPlayer(int iId): Player(iId) {} 00093 virtual ~HumanPlayer() {} 00094 00095 // Pseudo RTTI 00096 virtual bool isHuman() const { return true; } 00097 }; 00098 00099 #endif 00100 00101 /// Local Variables: 00102 /// mode: c++ 00103 /// mode: hs-minor 00104 /// c-basic-offset: 4 00105 /// indent-tabs-mode: nil 00106 /// End: