diff --git a/src/engine/handinterface.h b/src/engine/handinterface.h index 6504dcc2..35ba80bb 100644 --- a/src/engine/handinterface.h +++ b/src/engine/handinterface.h @@ -33,6 +33,8 @@ public: virtual ~HandInterface(); + virtual void start() = 0; + virtual PlayerInterface** getPlayerArray() const =0; virtual BoardInterface* getBoard() const =0; virtual PreflopInterface* getPreflop() const =0; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index ac46003b..75ef0dea 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -44,12 +44,6 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe for(i=0; isetMyRoundStartCash(playerArray[i]->getMyCash()); } - - - // Dealer, SB, BB bestimmen - assignButtons(); - -// myGui->refreshAll(); // Karten generieren und Board sowie Player zuweisen Tools myTool; @@ -64,7 +58,6 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe tempPlayerAndBoardArray[i+2] = cardsArray[i]; } - k = 0; myBoard->setMyCards(tempBoardArray); for(i=0; isetMyCardsFlip(0); + } // // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // @@ -154,31 +153,14 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe // // // seven-two, the others have Ace-King, Ace-Jack, Ace-Nine. The pot is obviously split. - - - - - - ///////////////////// - - // Karten austeilen - myGui->dealHoleCards(); - - // myFlipCards auf 0 setzen - for(i=0; isetMyCardsFlip(0); - } + // Dealer, SB, BB bestimmen + assignButtons(); // Preflop, Flop, Turn und River erstellen myPreflop = myFactory->createPreflop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); myFlop = myFactory->createFlop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); myRiver = myFactory->createRiver(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); - - //Rundenwechsel | beim ersten Durchlauf --> Preflop starten - myGui->nextPlayerAnimation(); - - delete[] cardsArray; } @@ -197,6 +179,20 @@ LocalHand::~LocalHand() } +void LocalHand::start() { + + ///////////////////// + + // Karten austeilen + myGui->dealHoleCards(); + + getBoard()->collectSets(); + getGuiInterface()->refreshPot(); + + //Rundenwechsel | beim ersten Durchlauf --> Preflop starten + myGui->nextPlayerAnimation(); +} + void LocalHand::assignButtons() { int i; diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index edc48f81..376573bd 100755 --- a/src/engine/local_engine/localhand.h +++ b/src/engine/local_engine/localhand.h @@ -37,11 +37,11 @@ class LocalHand : public HandInterface{ public: - LocalHand(EngineFactory*, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int); + LocalHand(EngineFactory*, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int); - ~LocalHand(); - - + ~LocalHand(); + + void start(); PlayerInterface** getPlayerArray() const { return playerArray; } BoardInterface* getBoard() const { return myBoard; } diff --git a/src/engine/local_engine/localpreflop.cpp b/src/engine/local_engine/localpreflop.cpp index 4cb62463..06156615 100755 --- a/src/engine/local_engine/localpreflop.cpp +++ b/src/engine/local_engine/localpreflop.cpp @@ -27,10 +27,6 @@ using namespace std; LocalPreflop::LocalPreflop(HandInterface* bR, int id, int qP, int dP, int sB) : PreflopInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), bigBlindPosition(0), smallBlind(sB), highestSet(2*sB), preflopFirstRound(1), playersTurn(0) { - - myHand->getBoard()->collectSets(); - myHand->getGuiInterface()->refreshPot(); - // // BigBlind ermitteln bigBlindPosition = dealerPosition; while (myHand->getPlayerArray()[bigBlindPosition]->getMyButton() != 3) { diff --git a/src/game.cpp b/src/game.cpp index 5dec6a8c..aa5aa997 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -82,12 +82,6 @@ Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameDa playerArray[i] = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); } actualBoard->setPlayer(playerArray); - - //// SPIEL-SCHLEIFE - - startHand(); - - // SPIEL-SCHLEIFE } @@ -115,7 +109,7 @@ HandInterface * Game::getCurrentHand() return actualHand; } -void Game::startHand() +void Game::initHand() { int i; @@ -150,20 +144,22 @@ void Game::startHand() // Hand erstellen actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash); - //GUI bereinigen - myGui->nextRoundCleanGui(); - - //Spielernamen schreiben -// myGui->refreshPlayerName(); - // Dealer-Button weiterschieben --> Achtung inactive do { dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS); } while(!(playerArray[dealerPosition]->getMyActiveStatus())); + // Abfrage Cash==0 -> player inactive -> actualQuantityPlayer-- +} + +void Game::startHand() +{ + assert(actualHand); + + //GUI bereinigen + myGui->nextRoundCleanGui(); myGui->logNewGameHandMsg(myGameID, actualHandID); - - // Abfrage Cash==0 -> player inactive -> actualQuantityPlayer-- + actualHand->start(); } diff --git a/src/game.h b/src/game.h index 74cccb43..82ae0e30 100755 --- a/src/game.h +++ b/src/game.h @@ -41,6 +41,9 @@ public: ~Game(); + void initHand(); + void startHand(); + HandInterface *getCurrentHand(); //Zufgriff Startvariablen @@ -71,12 +74,6 @@ public: void setActualHandID(const int& theValue) { actualHandID = theValue; } int getActualHandID() const { return actualHandID; } - void startHand(); - - - - - private: EngineFactory *myFactory; diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 26dc9152..742fd7fc 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include class Session; diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index f16edc21..848c08a2 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -44,7 +44,7 @@ GuiWrapper::~GuiWrapper() void GuiWrapper::initGui(int speed) { myW->initGui(speed); } -Session &GuiWrapper::getSession() { return myW->getSession(); } +Session &GuiWrapper::getSession() { return myW->getSession(); } void GuiWrapper::setSession(boost::shared_ptr session) { myW->setSession(session); } bool GuiWrapper::isNetworkServer() const { /* TODO hack */ return false; } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index d88c17c4..356f4cf8 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -42,7 +42,7 @@ public: void initGui(int speed); Session &getSession(); - void setSession(boost::shared_ptr session); + void setSession(boost::shared_ptr session); bool isNetworkServer() const; void waitForNetworkAction(GameState state, unsigned uniquePlayerId); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index a446accf..a449ca80 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -34,8 +34,8 @@ #include "playerinterface.h" #include "boardinterface.h" -#include "handinterface.h" -#include "game.h" +#include "handinterface.h" +#include "game.h" #include "session.h" #include "log.h" @@ -2037,7 +2037,9 @@ void mainWindowImpl::showMyCards() { void mainWindowImpl::startNewHand() { - if( !breakAfterActualHand){ mySession->getCurrentGame()->startHand(); + if( !breakAfterActualHand){ + mySession->getCurrentGame()->initHand(); + mySession->getCurrentGame()->startHand(); } else { pushButton_break->setDisabled(FALSE); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index dd1274f0..25632c11 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index 8bd31fe3..9afe3b1a 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -32,6 +32,7 @@ using namespace std; + class ServerSenderCallback : public SenderCallback { public: @@ -141,7 +142,7 @@ ServerRecvThread::NotificationLoop() switch(notification.message) { case NOTIFY_GAME_START: - SetState(SERVER_START_GAME_STATE::Instance()); + InternalStartGame(); break; case NOTIFY_WAIT_FOR_CLIENT_ACTION: break; @@ -243,6 +244,13 @@ ServerRecvThread::CleanupSessionMap() m_sessionMap.clear(); } +void +ServerRecvThread::InternalStartGame() +{ +// m_game.reset(...); + SetState(SERVER_START_GAME_STATE::Instance()); +} + boost::shared_ptr ServerRecvThread::GetSession(SOCKET sock) { @@ -468,6 +476,13 @@ ServerRecvThread::GetReceiver() return *m_receiver; } +Game & +ServerRecvThread::GetGame() +{ + assert(m_game.get()); + return *m_game; +} + const GameData & ServerRecvThread::GetGameData() const { diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index d5aa9249..e3591633 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -45,6 +45,7 @@ class ReceiverHelper; class ServerSenderCallback; class NetPacket; struct GameData; +class Game; class ServerRecvThread : public Thread { @@ -86,6 +87,8 @@ protected: void CleanupConnectQueue(); void CleanupSessionMap(); + void InternalStartGame(); + boost::shared_ptr GetSession(SOCKET sock); void AddSession(boost::shared_ptr sessionData); void SessionError(boost::shared_ptr sessionData, int errorCode); @@ -108,6 +111,7 @@ protected: SenderThread &GetSender(); ReceiverHelper &GetReceiver(); + Game &GetGame(); const GameData &GetGameData() const; bool CheckPassword(const std::string &password) const; @@ -130,8 +134,9 @@ private: std::auto_ptr m_receiver; std::auto_ptr m_sender; - std::auto_ptr m_senderCallback; + std::auto_ptr m_game; std::auto_ptr m_gameData; + std::auto_ptr m_senderCallback; std::string m_password; diff --git a/src/session.cpp b/src/session.cpp index 33fe106e..83a50e5a 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -75,6 +75,11 @@ void Session::startGame(const GameData &gameData) { playerDataList.push_back(playerData); } currentGame = new Game(myGui, playerDataList, gameData, currentGameID); + + //// SPIEL-SCHLEIFE + currentGame->initHand(); + currentGame->startHand(); + // SPIEL-SCHLEIFE } void Session::deleteGame() { @@ -172,10 +177,3 @@ void Session::terminateNetworkServer() myNetServer = 0; } -bool Session::isNetworkServerRunning() const -{ - // TODO: Hack - // TODO: Every function which calls this function is also hacked. - return myNetServer != 0; -} - diff --git a/src/session.h b/src/session.h index 287ed22f..5a177788 100755 --- a/src/session.h +++ b/src/session.h @@ -50,8 +50,6 @@ public: void waitForNetworkServerAction(GameState state, unsigned uniquePlayerId); void terminateNetworkServer(); - bool isNetworkServerRunning() const; - void setCurrentGameID(const int& theValue) { currentGameID = theValue; } int getCurrentGameID() const { return currentGameID; }