diff --git a/pokerth.pro b/pokerth.pro index 49cda788..b927d01f 100755 --- a/pokerth.pro +++ b/pokerth.pro @@ -54,6 +54,7 @@ INCLUDEPATH += . \ # Input HEADERS += src/game.h \ src/session.h \ + src/playerdata.h \ src/config/configfile.h \ src/core/rand.h \ src/core/thread.h \ @@ -119,6 +120,7 @@ FORMS += src/gui/qt/mainwindow.ui \ SOURCES += src/game.cpp \ src/pokerth.cpp \ src/session.cpp \ + src/playerdata.cpp \ src/config/configfile.cpp \ src/engine/boardinterface.cpp \ src/engine/enginefactory.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 3d5437a0..6b9d827c 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -27,14 +27,16 @@ #include "playerinterface.h" #include "handinterface.h" -#include "configfile.h" - using namespace std; -Game::Game(ConfigFile* c, GuiInterface* g, int qP, int sC, int sB, int gId) : myConfig(c), myGui(g), actualHand(0), actualBoard(0), startQuantityPlayers(qP), startCash(sC), startSmallBlind(sB), myGameID(gId), actualQuantityPlayers(qP), actualSmallBlind(sB), actualHandID(0), dealerPosition(0) +Game::Game(GuiInterface* gui, const PlayerDataList &playerData, int sC, int sB, int hbrsB, int gameId) +: myGui(gui), actualHand(0), actualBoard(0), startCash(sC), + startSmallBlind(sB), startHandsBeforeRaiseSmallBlind(hbrsB),myGameID(gameId), + actualSmallBlind(sB), actualHandID(0), dealerPosition(0) { // cout << "Create Game Object" << "\n"; int i; + startQuantityPlayers = actualQuantityPlayers = playerData.size(); actualHandID = 0; @@ -57,23 +59,26 @@ Game::Game(ConfigFile* c, GuiInterface* g, int qP, int sC, int sB, int gId) : my myTool.getRandNumber(0, startQuantityPlayers-1, 1, &dealerPosition, 0); // Player erstellen - PlayerInterface *tempPlayer; + PlayerDataList::const_iterator player_i = playerData.begin(); + PlayerDataList::const_iterator player_end = playerData.end(); for(i=0; iGetName(); + myAvatarFile = (*player_i)->GetAvatarFile(); + // TODO: set player type + ++player_i; + } //PlayerObjekte erzeugen - tempPlayer = myFactory->createPlayer(actualBoard, i, myConfig->readConfigString(myName.str()), myConfig->readConfigString(myAvatar.str()), startCash, startQuantityPlayers > i, 0); - playerArray[i] = tempPlayer; + playerArray[i] = myFactory->createPlayer(actualBoard, i, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); } actualBoard->setPlayer(playerArray); - + //// SPIEL-SCHLEIFE startHand(); @@ -116,8 +121,7 @@ void Game::startHand() actualHandID++; // smallBlind alle x Runden erhöhen - int handsBeforeRaiseSmallBLind = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind"); - if(actualHandID%handsBeforeRaiseSmallBLind == 0) actualSmallBlind *= 2; + if(actualHandID%startHandsBeforeRaiseSmallBlind == 0) actualSmallBlind *= 2; //Spieler Action auf 0 setzen for(i=0; i #include "game_defs.h" +#include "playerdata.h" class GuiInterface; class HandInterface; class PlayerInterface; class BoardInterface; class EngineFactory; -class ConfigFile; class Game { public: - Game(ConfigFile*, GuiInterface*, int, int, int, int); + Game(GuiInterface *gui, const PlayerDataList &playerData, int sC, int sB, int hbrsB, int gameId); ~Game(); @@ -69,9 +69,6 @@ public: void setActualHandID(const int& theValue) { actualHandID = theValue; } int getActualHandID() const { return actualHandID; } - void setRoundsToRaiseSmallBlind(const int& theValue) { roundsToRaiseSmallBlind = theValue; } - int getRoundsToRaiseSmallBlind() const { return roundsToRaiseSmallBlind; } - void startHand(); @@ -82,8 +79,6 @@ public: private: EngineFactory *myFactory; - ConfigFile *myConfig; - GuiInterface *myGui; HandInterface *actualHand; BoardInterface *actualBoard; @@ -93,6 +88,7 @@ private: int startQuantityPlayers; int startCash; int startSmallBlind; + int startHandsBeforeRaiseSmallBlind; int myGameID; //Laufvariablen @@ -100,10 +96,6 @@ private: int actualSmallBlind; int actualHandID; int dealerPosition; - - int roundsToRaiseSmallBlind; - - }; #endif diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index c6db8293..d7a43a21 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -608,7 +608,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { //positioning Slider horizontalSlider_speed->setValue(guiGameSpeed); //Start Game!!! - mySession->startGame(v->spinBox_quantityPlayers->value(), v->spinBox_startCash->value(), v->spinBox_smallBlind->value()); + mySession->startGame(v->spinBox_quantityPlayers->value(), v->spinBox_startCash->value(), v->spinBox_smallBlind->value(), v->spinBox_handsBeforeRaiseSmallBlind->value()); } // start with default values else { @@ -618,7 +618,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { //positioning Slider horizontalSlider_speed->setValue(guiGameSpeed); //Start Game!!! - mySession->startGame(myConfig->readConfigInt("NumberOfPlayers"), myConfig->readConfigInt("StartCash"), myConfig->readConfigInt("SmallBlind")); + mySession->startGame(myConfig->readConfigInt("NumberOfPlayers"), myConfig->readConfigInt("StartCash"), myConfig->readConfigInt("SmallBlind"), myConfig->readConfigInt("HandsBeforeRaiseSmallBlind")); } } diff --git a/src/net/netpacket.h b/src/net/netpacket.h index 85156c66..949df045 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -21,8 +21,7 @@ #ifndef _NETPACKET_H_ #define _NETPACKET_H_ -#include -#include +#include #include #define MIN_PACKET_SIZE 4 @@ -30,12 +29,6 @@ #define MAX_NAME_SIZE 64 #define MAX_PASSWORD_SIZE 64 -// TODO: move this somewhere else -enum PlayerType -{ - PLAYER_TYPE_COMPUTER, - PLAYER_TYPE_HUMAN -}; enum JoinGameErrorReason { diff --git a/src/playerdata.cpp b/src/playerdata.cpp new file mode 100644 index 00000000..9a01f7a1 --- /dev/null +++ b/src/playerdata.cpp @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + +PlayerData::PlayerData() +: m_type(PLAYER_TYPE_COMPUTER) +{ +} + +PlayerData::~PlayerData() +{ +} + diff --git a/src/playerdata.h b/src/playerdata.h new file mode 100644 index 00000000..0c7d7d56 --- /dev/null +++ b/src/playerdata.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Player data. */ + +#ifndef _PLAYERDATA_H_ +#define _PLAYERDATA_H_ + +#include +#include +#include + +enum PlayerType +{ + PLAYER_TYPE_COMPUTER, + PLAYER_TYPE_HUMAN +}; + +class PlayerData +{ +public: + PlayerData(); + ~PlayerData(); + + const std::string &GetName() const + {return m_name;} + void SetName(const std::string &name) + {m_name = name;} + const std::string &GetAvatarFile() const + {return m_avatarFile;} + void SetAvatarFile(const std::string &avatarFile) + {m_avatarFile = avatarFile;} + PlayerType GetType() const + {return m_type;} + void SetPlayerType(PlayerType type) + {m_type = type;} + +private: + std::string m_name; + std::string m_avatarFile; + PlayerType m_type; +}; + +typedef std::list > PlayerDataList; + +#endif + diff --git a/src/session.cpp b/src/session.cpp index 9e9bf7bd..5e8f682d 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -30,7 +30,7 @@ using namespace std; Session::Session(GuiInterface *g) -: actualGameID(0), myNetClient(0), myNetServer(0), actualGame(0), myGui(g) +: currentGameID(0), myNetClient(0), myNetServer(0), actualGame(0), myGui(g) { myConfig = new ConfigFile; } @@ -46,11 +46,32 @@ Session::~Session() } -void Session::startGame(int qP, int sC, int sB) { +void Session::startGame(int qP, int sC, int sB, int hbrsB) { - actualGameID++; + currentGameID++; - actualGame = new Game(myConfig, myGui, qP, sC, sB, actualGameID); + PlayerDataList playerDataList; + for(int i=0; i playerData(new PlayerData); + playerData->SetName(myConfig->readConfigString(myName.str())); + playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str())); + + playerDataList.push_back(playerData); + } + + + actualGame = new Game(myGui, playerDataList, sC, sB, hbrsB, currentGameID); } void Session::deleteGame() { diff --git a/src/session.h b/src/session.h index cce53793..f956ed5f 100755 --- a/src/session.h +++ b/src/session.h @@ -34,7 +34,7 @@ public: ~Session(); - void startGame(int, int, int); + void startGame(int qP, int sC, int sB, int hbrsB); void deleteGame(); void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, const std::string &pwd); @@ -45,14 +45,12 @@ public: void initiateNetworkServerGame(); void terminateNetworkServer(); - void setActualGameID(const int& theValue) { actualGameID = theValue; } - int getActualGameID() const { return actualGameID; } - -// void createConfig(); + void setCurrentGameID(const int& theValue) { currentGameID = theValue; } + int getCurrentGameID() const { return currentGameID; } private: - int actualGameID; + int currentGameID; ClientThread *myNetClient; ServerThread *myNetServer;