Changes in preparation for the integration of the network server. GUI does not directly know Game and Hand any more, only Session. WARNING: This version crashes due to initialization order problems.

This commit is contained in:
lotodore
2007-05-11 12:01:13 +00:00
parent a37fe9969e
commit 7c6337d810
20 changed files with 441 additions and 323 deletions
+9 -6
View File
@@ -22,11 +22,12 @@
#include <net/clientcallback.h>
#include <net/servercallback.h>
#include <game_defs.h>
#include <string>
#include <boost/shared_ptr.hpp>
class Game;
class Session;
class HandInterface;
class GuiInterface : public ClientCallback, public ServerCallback {
@@ -34,10 +35,12 @@ public:
virtual ~GuiInterface();
virtual void initGui(int speed) =0;
//set
virtual void setGame(Game*) =0;
virtual void setHand(HandInterface*) =0;
virtual void setSession(Session*) =0;
virtual Session &getSession() =0;
virtual void setSession(boost::shared_ptr<Session> session) =0;
virtual bool isNetworkServer() const =0;
virtual void waitForNetworkAction(GameState state, unsigned uniquePlayerId) =0;
//refresh-Funktionen
virtual void refreshSet() const=0;
+6 -3
View File
@@ -19,6 +19,7 @@
***************************************************************************/
#include "guiwrapper.h"
#include "session.h"
using namespace std;
@@ -43,9 +44,11 @@ GuiWrapper::~GuiWrapper()
void GuiWrapper::initGui(int speed) { myW->initGui(speed); }
void GuiWrapper::setGame(Game *g) { myW->setGame(g); }
void GuiWrapper::setHand(HandInterface *lh) { myW->setHand(lh); }
void GuiWrapper::setSession(Session *s) { myW->setSession(s); }
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; }
void GuiWrapper::waitForNetworkAction(GameState state, unsigned uniquePlayerId) { /* TODO hack */ }
void GuiWrapper::refreshSet() const { myW->refreshSet(); }
void GuiWrapper::refreshCash() const { myW->refreshCash(); }
+8 -9
View File
@@ -30,23 +30,22 @@
#include <string>
#include <iostream>
#include "handinterface.h"
#include "session.h"
#include "game.h"
class Session;
class GuiWrapper : public GuiInterface
{
public:
GuiWrapper();
GuiWrapper();
~GuiWrapper();
~GuiWrapper();
void initGui(int speed);
void setGame(Game*);
void setHand(HandInterface*);
void setSession(Session*);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
bool isNetworkServer() const;
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
void refreshSet() const;
void refreshCash() const;
+32 -27
View File
@@ -20,6 +20,9 @@
#include "log.h"
#include "mainwindowimpl.h"
#include <handinterface.h>
#include <session.h>
#include <game.h>
#include <game_defs.h>
using namespace std;
@@ -149,44 +152,45 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
//Aktive Spieler zählen
int activePlayersCounter = 0;
HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand();
for (k=0; k<MAX_NUMBER_OF_PLAYERS; k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
if (currentHand->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
k = 0;
if(activePlayersCounter > 2) {
for(i=0; i<myW->getActualHand()->getStartQuantityPlayers(); i++) {
for(i=0; i<currentHand->getStartQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus()) {
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
//print cash only for active players
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 1) {
if(currentHand->getPlayerArray()[i]->getMyButton() == 1) {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
}
}
}
else {
for(i=0; i<myW->getActualHand()->getStartQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus()) {
for(i=0; i<currentHand->getStartQuantityPlayers(); i++) {
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
//print cash only for active players
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 3) {
if(currentHand->getPlayerArray()[i]->getMyButton() == 3) {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
else {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
}
}
@@ -198,17 +202,17 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
//Aktive Spieler zählen
int activePlayersCounter = 0;
for (k=0; k<MAX_NUMBER_OF_PLAYERS; k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
if (currentHand->getPlayerArray()[k]->getMyAction() != 1 && currentHand->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
if(activePlayersCounter < 3) { j=1; }
// cout << activePlayersCounter << endl;
// cout << (i+myW->getActualHand()->getDealerPosition()+j)%5 << endl;
// cout << (i+currentHand->getDealerPosition()+j)%5 << endl;
switch (myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) {
case 2 : stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), ";
switch (currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) {
case 2 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), ";
break;
case 3 : stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)";
case 3 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)";
break;
default :;
}
@@ -226,18 +230,19 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
void Log::logPlayerWinsMsg(int playerID, int pot) {
int i;
HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand();
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
// if (cardsValueInt != -1) {
// myW->textBrowser_Log->append(QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! ");
// stream << "</br><i>"+QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! ");
// stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// }
// else {
myW->textBrowser_Log->append(QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! ");
stream << "</br><i>"+QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! ");
stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// }
myLogFile->close();
@@ -340,20 +345,20 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
// Kicker anzeigen?
// for(i=0; i<5; i++) {
// if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// sameHandCounter++;
// if(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt();
// if(currentHand->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = currentHand->getPlayerArray()[i]->getMyCardsValueInt();
// }
// }
// }
// Unterschied ermitteln
// for(i=0; i<5; i++) {
// if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// sameHandCounter++;
// if(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt();
// if(currentHand->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = currentHand->getPlayerArray()[i]->getMyCardsValueInt();
// }
// }
// }
@@ -364,7 +369,7 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
/* } else {
if(cardsValueInt == tempHighestCardsValueInt) {
for(i=0; i<5; i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) ;
if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) ;
}
}
}*/
File diff suppressed because it is too large Load Diff
+9 -16
View File
@@ -21,20 +21,19 @@
#define MAINWINDOWIMPL_H
#include "ui_mainwindow.h"
#include "game_defs.h"
#include <gamedata.h>
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <QtGui>
#include <QtCore>
#include "handinterface.h"
#include "game_defs.h"
#include <gamedata.h>
class Session;
class Game;
class Log;
class ConfigFile;
class Session;
class BoardInterface;
// class HandInterface;
@@ -60,15 +59,11 @@ public:
void initGui(int speed);
void setGame(Game*);
void setHand(HandInterface*);
void setSession(Session*);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
void setLog(Log*);
void setActualHand(HandInterface* theValue) { actualHand = theValue;}
HandInterface* getActualHand() const { return actualHand;}
//refresh-Funktionen
void refreshSet();
void refreshButton();
@@ -203,9 +198,7 @@ public slots:
private:
Game *actualGame;
HandInterface *actualHand;
Session *mySession;
boost::shared_ptr<Session> mySession;
Log *myLog;
ConfigFile *myConfig;