Two step initialization for engine. First step: Create and initialize objects (constructor). Second step: Start the engine, update the UI.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -44,12 +44,6 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe
|
||||
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||
playerArray[i]->setMyRoundStartCash(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; i<startQuantityPlayers; i++) {
|
||||
@@ -93,6 +86,12 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe
|
||||
k++;
|
||||
}
|
||||
}
|
||||
delete[] cardsArray;
|
||||
|
||||
// myFlipCards auf 0 setzen
|
||||
for(i=0; i<startQuantityPlayers; i++) {
|
||||
playerArray[i]->setMyCardsFlip(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; i<startQuantityPlayers; i++) {
|
||||
playerArray[i]->setMyCardsFlip(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;
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+11
-15
@@ -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();
|
||||
}
|
||||
|
||||
+3
-6
@@ -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;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <net/servercallback.h>
|
||||
#include <game_defs.h>
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
||||
class Session;
|
||||
|
||||
@@ -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> session) { myW->setSession(session); }
|
||||
|
||||
bool GuiWrapper::isNetworkServer() const { /* TODO hack */ return false; }
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void initGui(int speed);
|
||||
|
||||
Session &getSession();
|
||||
void setSession(boost::shared_ptr<Session> session);
|
||||
void setSession(boost::shared_ptr<Session> session);
|
||||
|
||||
bool isNetworkServer() const;
|
||||
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <net/sendercallback.h>
|
||||
#include <net/receiverhelper.h>
|
||||
#include <net/socket_msg.h>
|
||||
#include <gamedata.h>
|
||||
#include <game.h>
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
|
||||
@@ -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<SessionData>
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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<SessionData> GetSession(SOCKET sock);
|
||||
void AddSession(boost::shared_ptr<SessionData> sessionData);
|
||||
void SessionError(boost::shared_ptr<SessionData> 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<ReceiverHelper> m_receiver;
|
||||
std::auto_ptr<SenderThread> m_sender;
|
||||
|
||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||
std::auto_ptr<Game> m_game;
|
||||
std::auto_ptr<GameData> m_gameData;
|
||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||
|
||||
std::string m_password;
|
||||
|
||||
|
||||
+5
-7
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user