Files
pokerth/src/game.cpp
T

159 lines
4.7 KiB
C++
Raw Normal View History

2007-01-13 02:40:33 +00:00
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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 "game.h"
2007-01-13 20:47:48 +00:00
#include "enginefactory.h"
#include "localenginefactory.h"
2007-01-13 02:40:33 +00:00
#include "guiinterface.h"
2007-01-13 20:47:48 +00:00
#include "boardinterface.h"
#include "playerinterface.h"
#include "handinterface.h"
2007-01-22 22:25:58 +00:00
#include "configfile.h"
2007-01-13 02:40:33 +00:00
using namespace std;
2007-04-20 23:14:08 +00:00
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)
2007-01-13 02:40:33 +00:00
{
// cout << "Create Game Object" << "\n";
2007-01-13 02:40:33 +00:00
int i;
actualHandID = 0;
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
playerArray[i] = 0;
}
2007-01-13 14:27:56 +00:00
myGui->setGame(this);
2007-01-13 20:47:48 +00:00
//EngineFactory erstellen
myFactory = new LocalEngineFactory; // LocalEngine erstellen
2007-01-13 02:40:33 +00:00
// Board erstellen
2007-01-13 22:29:17 +00:00
actualBoard = myFactory->createBoard();
2007-01-13 02:40:33 +00:00
// ersten Dealer bestimmen
Tools myTool;
myTool.getRandNumber(0, startQuantityPlayers-1, 1, &dealerPosition, 0);
// Player erstellen
2007-01-13 22:29:17 +00:00
PlayerInterface *tempPlayer;
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-19 19:13:59 +00:00
2007-03-29 00:15:43 +00:00
//Namen und Avatarpfad abfragen
2007-01-22 22:25:58 +00:00
ostringstream myName;
2007-02-03 22:47:16 +00:00
if (i==0) { myName << "MyName"; }
else { myName << "Opponent" << i << "Name"; }
2007-03-29 00:15:43 +00:00
ostringstream myAvatar;
if (i==0) { myAvatar << "MyAvatar"; }
else { myAvatar << "Opponent" << i << "Avatar"; }
2007-01-19 19:13:59 +00:00
2007-01-22 22:25:58 +00:00
//PlayerObjekte erzeugen
2007-04-20 23:14:08 +00:00
tempPlayer = myFactory->createPlayer(actualBoard, i, myConfig->readConfigString(myName.str()), myConfig->readConfigString(myAvatar.str()), startCash, startQuantityPlayers > i, 0);
2007-01-13 02:40:33 +00:00
playerArray[i] = tempPlayer;
}
actualBoard->setPlayer(playerArray);
//// SPIEL-SCHLEIFE
startHand();
// SPIEL-SCHLEIFE
}
Game::~Game()
{
// cout << "Delete Game Object" << "\n";
2007-01-13 02:40:33 +00:00
int i;
delete actualBoard;
actualBoard = 0;
delete actualHand;
actualHand = 0;
2007-01-13 22:29:17 +00:00
PlayerInterface *tempPlayer;
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
tempPlayer = playerArray[i];
playerArray[i] = 0;
delete tempPlayer;
}
}
void Game::startHand()
{
int i;
// eventuell vorhandene Hand löschen
2007-01-13 02:40:33 +00:00
if(actualHand) {
delete actualHand;
actualHand = 0;
}
actualHandID++;
2007-01-23 19:20:18 +00:00
// smallBlind alle x Runden erhöhen
2007-02-03 22:47:16 +00:00
int handsBeforeRaiseSmallBLind = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind");
2007-01-23 19:20:18 +00:00
if(actualHandID%handsBeforeRaiseSmallBLind == 0) actualSmallBlind *= 2;
2007-01-13 02:40:33 +00:00
//Spieler Action auf 0 setzen
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
playerArray[i]->setMyAction(0);
}
// Spieler mit leerem Cash auf inactive setzen
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
if(playerArray[i]->getMyCash() == 0) playerArray[i]->setMyActiveStatus(0);
}
// Anzahl noch aktiver Spieler ermitteln
actualQuantityPlayers = 0;
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
if(playerArray[i]->getMyActiveStatus() != 0) actualQuantityPlayers++;
}
2007-01-13 02:40:33 +00:00
// Hand erstellen
actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash);
2007-01-13 02:40:33 +00:00
2007-01-13 22:29:17 +00:00
2007-01-13 02:40:33 +00:00
//GUI bereinigen
2007-01-13 14:27:56 +00:00
myGui->nextRoundCleanGui();
2007-01-13 02:40:33 +00:00
//Spielernamen schreiben
2007-03-29 22:58:04 +00:00
// myGui->refreshPlayerName();
2007-01-13 02:40:33 +00:00
// Dealer-Button weiterschieben --> Achtung inactive
do {
dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS);
2007-01-13 02:40:33 +00:00
} while(!(playerArray[dealerPosition]->getMyActiveStatus()));
2007-02-04 13:46:27 +00:00
myGui->logNewGameHandMsg(myGameID, actualHandID);
2007-01-13 02:40:33 +00:00
// Abfrage Cash==0 -> player inactive -> actualQuantityPlayer--
}