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 ~HandInterface();
|
||||||
|
|
||||||
|
virtual void start() = 0;
|
||||||
|
|
||||||
virtual PlayerInterface** getPlayerArray() const =0;
|
virtual PlayerInterface** getPlayerArray() const =0;
|
||||||
virtual BoardInterface* getBoard() const =0;
|
virtual BoardInterface* getBoard() const =0;
|
||||||
virtual PreflopInterface* getPreflop() 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++) {
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||||
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
|
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Dealer, SB, BB bestimmen
|
|
||||||
assignButtons();
|
|
||||||
|
|
||||||
// myGui->refreshAll();
|
|
||||||
|
|
||||||
// Karten generieren und Board sowie Player zuweisen
|
// Karten generieren und Board sowie Player zuweisen
|
||||||
Tools myTool;
|
Tools myTool;
|
||||||
@@ -64,7 +58,6 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe
|
|||||||
tempPlayerAndBoardArray[i+2] = cardsArray[i];
|
tempPlayerAndBoardArray[i+2] = cardsArray[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
myBoard->setMyCards(tempBoardArray);
|
myBoard->setMyCards(tempBoardArray);
|
||||||
for(i=0; i<startQuantityPlayers; i++) {
|
for(i=0; i<startQuantityPlayers; i++) {
|
||||||
@@ -93,6 +86,12 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe
|
|||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete[] cardsArray;
|
||||||
|
|
||||||
|
// myFlipCards auf 0 setzen
|
||||||
|
for(i=0; i<startQuantityPlayers; i++) {
|
||||||
|
playerArray[i]->setMyCardsFlip(0);
|
||||||
|
}
|
||||||
|
|
||||||
// // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
|
// // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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.
|
// // // seven-two, the others have Ace-King, Ace-Jack, Ace-Nine. The pot is obviously split.
|
||||||
|
|
||||||
|
// Dealer, SB, BB bestimmen
|
||||||
|
assignButtons();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
// Karten austeilen
|
|
||||||
myGui->dealHoleCards();
|
|
||||||
|
|
||||||
// myFlipCards auf 0 setzen
|
|
||||||
for(i=0; i<startQuantityPlayers; i++) {
|
|
||||||
playerArray[i]->setMyCardsFlip(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preflop, Flop, Turn und River erstellen
|
// Preflop, Flop, Turn und River erstellen
|
||||||
myPreflop = myFactory->createPreflop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
myPreflop = myFactory->createPreflop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
||||||
myFlop = myFactory->createFlop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
myFlop = myFactory->createFlop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
||||||
myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
|
||||||
myRiver = myFactory->createRiver(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() {
|
void LocalHand::assignButtons() {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -37,11 +37,11 @@
|
|||||||
|
|
||||||
class LocalHand : public HandInterface{
|
class LocalHand : public HandInterface{
|
||||||
public:
|
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; }
|
PlayerInterface** getPlayerArray() const { return playerArray; }
|
||||||
BoardInterface* getBoard() const { return myBoard; }
|
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)
|
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
|
// // BigBlind ermitteln
|
||||||
bigBlindPosition = dealerPosition;
|
bigBlindPosition = dealerPosition;
|
||||||
while (myHand->getPlayerArray()[bigBlindPosition]->getMyButton() != 3) {
|
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);
|
playerArray[i] = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0);
|
||||||
}
|
}
|
||||||
actualBoard->setPlayer(playerArray);
|
actualBoard->setPlayer(playerArray);
|
||||||
|
|
||||||
//// SPIEL-SCHLEIFE
|
|
||||||
|
|
||||||
startHand();
|
|
||||||
|
|
||||||
// SPIEL-SCHLEIFE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +109,7 @@ HandInterface * Game::getCurrentHand()
|
|||||||
return actualHand;
|
return actualHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::startHand()
|
void Game::initHand()
|
||||||
{
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
@@ -150,20 +144,22 @@ void Game::startHand()
|
|||||||
// Hand erstellen
|
// Hand erstellen
|
||||||
actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash);
|
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
|
// Dealer-Button weiterschieben --> Achtung inactive
|
||||||
do {
|
do {
|
||||||
dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS);
|
dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS);
|
||||||
} while(!(playerArray[dealerPosition]->getMyActiveStatus()));
|
} while(!(playerArray[dealerPosition]->getMyActiveStatus()));
|
||||||
|
|
||||||
|
// Abfrage Cash==0 -> player inactive -> actualQuantityPlayer--
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::startHand()
|
||||||
|
{
|
||||||
|
assert(actualHand);
|
||||||
|
|
||||||
|
//GUI bereinigen
|
||||||
|
myGui->nextRoundCleanGui();
|
||||||
|
|
||||||
myGui->logNewGameHandMsg(myGameID, actualHandID);
|
myGui->logNewGameHandMsg(myGameID, actualHandID);
|
||||||
|
|
||||||
|
actualHand->start();
|
||||||
// Abfrage Cash==0 -> player inactive -> actualQuantityPlayer--
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -41,6 +41,9 @@ public:
|
|||||||
|
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
|
void initHand();
|
||||||
|
void startHand();
|
||||||
|
|
||||||
HandInterface *getCurrentHand();
|
HandInterface *getCurrentHand();
|
||||||
|
|
||||||
//Zufgriff Startvariablen
|
//Zufgriff Startvariablen
|
||||||
@@ -71,12 +74,6 @@ public:
|
|||||||
void setActualHandID(const int& theValue) { actualHandID = theValue; }
|
void setActualHandID(const int& theValue) { actualHandID = theValue; }
|
||||||
int getActualHandID() const { return actualHandID; }
|
int getActualHandID() const { return actualHandID; }
|
||||||
|
|
||||||
void startHand();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EngineFactory *myFactory;
|
EngineFactory *myFactory;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <net/servercallback.h>
|
#include <net/servercallback.h>
|
||||||
#include <game_defs.h>
|
#include <game_defs.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
|
||||||
class Session;
|
class Session;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ GuiWrapper::~GuiWrapper()
|
|||||||
|
|
||||||
void GuiWrapper::initGui(int speed) { myW->initGui(speed); }
|
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); }
|
void GuiWrapper::setSession(boost::shared_ptr<Session> session) { myW->setSession(session); }
|
||||||
|
|
||||||
bool GuiWrapper::isNetworkServer() const { /* TODO hack */ return false; }
|
bool GuiWrapper::isNetworkServer() const { /* TODO hack */ return false; }
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
void initGui(int speed);
|
void initGui(int speed);
|
||||||
|
|
||||||
Session &getSession();
|
Session &getSession();
|
||||||
void setSession(boost::shared_ptr<Session> session);
|
void setSession(boost::shared_ptr<Session> session);
|
||||||
|
|
||||||
bool isNetworkServer() const;
|
bool isNetworkServer() const;
|
||||||
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
|
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
|
||||||
|
|||||||
@@ -34,8 +34,8 @@
|
|||||||
#include "playerinterface.h"
|
#include "playerinterface.h"
|
||||||
#include "boardinterface.h"
|
#include "boardinterface.h"
|
||||||
|
|
||||||
#include "handinterface.h"
|
#include "handinterface.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@@ -2037,7 +2037,9 @@ void mainWindowImpl::showMyCards() {
|
|||||||
|
|
||||||
void mainWindowImpl::startNewHand() {
|
void mainWindowImpl::startNewHand() {
|
||||||
|
|
||||||
if( !breakAfterActualHand){ mySession->getCurrentGame()->startHand();
|
if( !breakAfterActualHand){
|
||||||
|
mySession->getCurrentGame()->initHand();
|
||||||
|
mySession->getCurrentGame()->startHand();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pushButton_break->setDisabled(FALSE);
|
pushButton_break->setDisabled(FALSE);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <net/sendercallback.h>
|
#include <net/sendercallback.h>
|
||||||
#include <net/receiverhelper.h>
|
#include <net/receiverhelper.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
#include <gamedata.h>
|
#include <game.h>
|
||||||
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
class ServerSenderCallback : public SenderCallback
|
class ServerSenderCallback : public SenderCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -141,7 +142,7 @@ ServerRecvThread::NotificationLoop()
|
|||||||
switch(notification.message)
|
switch(notification.message)
|
||||||
{
|
{
|
||||||
case NOTIFY_GAME_START:
|
case NOTIFY_GAME_START:
|
||||||
SetState(SERVER_START_GAME_STATE::Instance());
|
InternalStartGame();
|
||||||
break;
|
break;
|
||||||
case NOTIFY_WAIT_FOR_CLIENT_ACTION:
|
case NOTIFY_WAIT_FOR_CLIENT_ACTION:
|
||||||
break;
|
break;
|
||||||
@@ -243,6 +244,13 @@ ServerRecvThread::CleanupSessionMap()
|
|||||||
m_sessionMap.clear();
|
m_sessionMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerRecvThread::InternalStartGame()
|
||||||
|
{
|
||||||
|
// m_game.reset(...);
|
||||||
|
SetState(SERVER_START_GAME_STATE::Instance());
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<SessionData>
|
boost::shared_ptr<SessionData>
|
||||||
ServerRecvThread::GetSession(SOCKET sock)
|
ServerRecvThread::GetSession(SOCKET sock)
|
||||||
{
|
{
|
||||||
@@ -468,6 +476,13 @@ ServerRecvThread::GetReceiver()
|
|||||||
return *m_receiver;
|
return *m_receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game &
|
||||||
|
ServerRecvThread::GetGame()
|
||||||
|
{
|
||||||
|
assert(m_game.get());
|
||||||
|
return *m_game;
|
||||||
|
}
|
||||||
|
|
||||||
const GameData &
|
const GameData &
|
||||||
ServerRecvThread::GetGameData() const
|
ServerRecvThread::GetGameData() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class ReceiverHelper;
|
|||||||
class ServerSenderCallback;
|
class ServerSenderCallback;
|
||||||
class NetPacket;
|
class NetPacket;
|
||||||
struct GameData;
|
struct GameData;
|
||||||
|
class Game;
|
||||||
|
|
||||||
class ServerRecvThread : public Thread
|
class ServerRecvThread : public Thread
|
||||||
{
|
{
|
||||||
@@ -86,6 +87,8 @@ protected:
|
|||||||
void CleanupConnectQueue();
|
void CleanupConnectQueue();
|
||||||
void CleanupSessionMap();
|
void CleanupSessionMap();
|
||||||
|
|
||||||
|
void InternalStartGame();
|
||||||
|
|
||||||
boost::shared_ptr<SessionData> GetSession(SOCKET sock);
|
boost::shared_ptr<SessionData> GetSession(SOCKET sock);
|
||||||
void AddSession(boost::shared_ptr<SessionData> sessionData);
|
void AddSession(boost::shared_ptr<SessionData> sessionData);
|
||||||
void SessionError(boost::shared_ptr<SessionData> sessionData, int errorCode);
|
void SessionError(boost::shared_ptr<SessionData> sessionData, int errorCode);
|
||||||
@@ -108,6 +111,7 @@ protected:
|
|||||||
SenderThread &GetSender();
|
SenderThread &GetSender();
|
||||||
ReceiverHelper &GetReceiver();
|
ReceiverHelper &GetReceiver();
|
||||||
|
|
||||||
|
Game &GetGame();
|
||||||
const GameData &GetGameData() const;
|
const GameData &GetGameData() const;
|
||||||
bool CheckPassword(const std::string &password) const;
|
bool CheckPassword(const std::string &password) const;
|
||||||
|
|
||||||
@@ -130,8 +134,9 @@ private:
|
|||||||
std::auto_ptr<ReceiverHelper> m_receiver;
|
std::auto_ptr<ReceiverHelper> m_receiver;
|
||||||
std::auto_ptr<SenderThread> m_sender;
|
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<GameData> m_gameData;
|
||||||
|
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||||
|
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
|
|
||||||
|
|||||||
+5
-7
@@ -75,6 +75,11 @@ void Session::startGame(const GameData &gameData) {
|
|||||||
playerDataList.push_back(playerData);
|
playerDataList.push_back(playerData);
|
||||||
}
|
}
|
||||||
currentGame = new Game(myGui, playerDataList, gameData, currentGameID);
|
currentGame = new Game(myGui, playerDataList, gameData, currentGameID);
|
||||||
|
|
||||||
|
//// SPIEL-SCHLEIFE
|
||||||
|
currentGame->initHand();
|
||||||
|
currentGame->startHand();
|
||||||
|
// SPIEL-SCHLEIFE
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::deleteGame() {
|
void Session::deleteGame() {
|
||||||
@@ -172,10 +177,3 @@ void Session::terminateNetworkServer()
|
|||||||
myNetServer = 0;
|
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 waitForNetworkServerAction(GameState state, unsigned uniquePlayerId);
|
||||||
void terminateNetworkServer();
|
void terminateNetworkServer();
|
||||||
|
|
||||||
bool isNetworkServerRunning() const;
|
|
||||||
|
|
||||||
void setCurrentGameID(const int& theValue) { currentGameID = theValue; }
|
void setCurrentGameID(const int& theValue) { currentGameID = theValue; }
|
||||||
int getCurrentGameID() const { return currentGameID; }
|
int getCurrentGameID() const { return currentGameID; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user