Here's the whole class code, I just keep browsing it up and down and still can't find what went wrong:
class Cardwars{
var $game_id;
var $bet = 0;
var $tie = 0;
var $warbet = 0;
var $pointer = 0;
var $output = array();
var $deck = array();
var $betLines = array();
function Cardwars($game){
$this->game_id = $game['id'];
$this->deck = explode(",",$game['baralho']);
$this->bet = $game['bet'];
$this->tie = $game['tie'];
$this->pointer = $game['ponteiro'];
}
function init_game(){
$this->resetVars();
$this->output[] = ".$this->game_id."\" name=\"Cardwars\" response=\"init\">";
$this->output[] = "";
$this->output[] = "";
}
function getComponentOutput(){
global $x;
$x->addComponent(implode("\r\n",$this->output));
}
function resetVars(){
$sql = "UPDATE cardwars SET baralho='',ponteiro=0 WHERE id = " . $this->game_id;
mysql_query($sql);
}
function start_deck(){
$cartas = array("A","2","3","4","5","6","7","8","9","10","J","Q","K");
$naipes = array("c","s","d","h");
$baralho = array();
foreach($cartas as $c){
foreach($naipes as $n){
$baralho[] = $c . $n;
}
}
mt_srand(microtime() * 100000 + rand());
shuffle($baralho);
$this->deck = $baralho;
$this->pointer = 0;
mysql_query("UPDATE cardwars SET baralho = '".implode(",",$baralho)."', bet=0,tie=0,ponteiro=0 WHERE id = " . $this->game_id);
}
function getCardValue($card){
$cv = substr($card,0,1);
$cout = 0;
switch($cv){
case 'A': $cout = 14; break;
case '2': $cout = 2; break;
case '3': $cout = 3; break;
case '4': $cout = 4; break;
case '5': $cout = 5; break;
case '6': $cout = 6; break;
case '7': $cout = 7; break;
case '8': $cout = 8; break;
case '9': $cout = 9; break;
case '1': $cout = 10; break;
case 'J': $cout = 11; break;
case 'Q': $cout = 12; break;
case 'K': $cout = 13; break;
}
return $cout;
}
function deal(){
global $bank,$Player;
$this->output[] = '.$this->game_id.'" name="Cardwars" response="deal">';
if($this->bet > 0){
mysql_query("UPDATE cardwars SET bet = ". $this->bet. " WHERE id =" . $this->game_id);
}
if($this->tie > 0){
mysql_query("UPDATE cardwars SET tie = ". $this->tie. " WHERE id =" . $this->game_id);
}
$ucard = $this->deck[$this->pointer];
$this->pointer++;
$dcard = $this->deck[$this->pointer];
$this->pointer++;
$dcardVal = $this->getCardValue($dcard);
$ucardVal = $this->getCardValue($ucard);
$this->updatePointer();
if($dcardVal > $ucardVal){
$bank->method = "update";
$this->betLines[] = '.$this->bet.'" won="0" />';
if($this->tie > 0){
$this->betLines[] = '.$this->tie.'" won="0" />';
$bt = $this->tie + $this->bet;
$bank->addBalanceLineX(-$bt);
}else{
$bank->addBalanceLineX(-$this->bet);
$this->betLines[] = '';
}
$this->output[] = '.$ucard.'" dealer="'.$dcard.'" state="loss" />';
$this->resetVars();
}elseif($dcardVal < $ucardVal){
$bank->method = "update";
$betWin = $this->bet * 2;
$this->betLines[] = '.$this->bet.'" won="'.$betWin.'" />';
$bank->payPrize($betWin/100);
if($bank->play == "r"){
$Player->updateReal($betWin/100);
}else{
$Player->updateFree($betWin/100);
}
if($this->tie > 0){
$this->betLines[] = '.$this->tie.'" won="0" />';
$bt = $this->tie + $this->bet;
$bank->addBalanceLineX(-$this->tie);
}else{
$bank->addBalanceLineX($this->bet);
$this->betLines[] = '';
}
$this->output[] = '.$ucard.'" dealer="'.$dcard.'" state="win" />';
$this->resetVars();
}elseif($dcardVal == $ucardVal){
$bank->method = "update";
$this->betLines[] = '.$this->bet.'" won="0" />';
if($this->tie > 0){
$this->betLines[] = '.$this->tie.'" won="0" />';
$bt = $this->tie + $this->bet;
$bank->addBalanceLineX(-$bt);
}else{
$bank->addBalanceLineX(-$this->bet);
$this->betLines[] = '';
}
$this->output[] = '.$ucard.'" dealer="'.$dcard.'" state="tie" />';
}
if(!empty($this->betLines)) $this->output[] = implode("\r\n",$this->betLines);
$this->output[] = "";
}
function surrender(){
global $bank,$Player;
$bank->method = "update";
$this->output[] = '.$this->game_id.'" name="Cardwars" response="surrender">';
$this->output[] = '';
$bwon = $this->bet /2;
$this->betLines[] = '.$bwon.'" won="'.$bwon.'" />';
$this->betLines[] = '.$bwon.'" won="0" />';
$bank->addBalanceLineX($bwon);
$bank->payPrize($bwon/100);
if($bank->play == "r"){
$Player->updateReal($bwon/100);
}else{
$Player->updateFree($bwon/100);
}
if($this->tie > 0){
$tieWon = ($this->tie * 10) + $this->tie;
$this->betLines[] = '.$this->tie.'" won="'.$tieWon.'" />';
$bank->addBalanceLineX($tieWon);
$bank->payPrize($tieWon/100);
if($bank->play == "r"){
$Player->updateReal($tieWon/100);
}else{
$Player->updateFree($tieWon/100);
}
}else{
$this->betLines[] = '';
}
if(!empty($this->betLines)) $this->output[] = implode("\r\n",$this->betLines);
$this->output[] = "";
$this->resetVars();
}
function war(){
global $bank,$Player;
$this->output[] = '.$this->game_id.'" name="Cardwars" response="war">';
$ucard = $this->deck[$this->pointer];
$this->pointer++;
$dcard = $this->deck[$this->pointer];
$this->pointer++;
$dcardVal = $this->getCardValue($dcard);
$ucardVal = $this->getCardValue($ucard);
$this->updatePointer();
if($dcardVal > $ucardVal){
$bank->method = "update";
$this->betLines[] = '.$this->bet.'" won="0" />';
$this->betLines[] = '.$this->bet.'" won="0" />';
if($this->tie > 0){
$tieWon = ($this->tie * 10) + $this->tie;
$this->betLines[] = '.$this->tie.'" won="'.$tieWon.'" />';
$bank->addBalanceLineX($tieWon);
$bank->payPrize($tieWon/100);
if($bank->play == "r"){
$Player->updateReal($tieWon/100);
}else{
$Player->updateFree($tieWon/100);
}
}else{
$bank->addBalanceLineX(-$this->bet);
$this->betLines[] = '';
}
$this->output[] = '.$ucard.'" dealer="'.$dcard.'" state="loss" />';
}else{
$bank->method = "update";
$betWin = $this->bet * 2;
$this->betLines[] = '.$this->bet.'" won="'.$betWin.'" />';
$this->betLines[] = '.$this->bet.'" won="'.$betWin.'" />';
$bank->payPrize(($betWin * 2)/100);
if($bank->play == "r"){
$Player->updateReal(($betWin * 2)/100);
}else{
$Player->updateFree(($betWin * 2)/100);
}
if($this->tie > 0){
$tieWon = ($this->tie * 10) + $this->tie;
$this->betLines[] = '.$this->tie.'" won="'.$tieWon.'" />';
$bank->addBalanceLineX($tieWon);
$bank->payPrize($tieWon/100);
if($bank->play == "r"){
$Player->updateReal($tieWon/100);
}else{
$Player->updateFree($tieWon/100);
}
}else{
$bank->addBalanceLineX($this->bet * 2);
$bank->addBalanceLineX($this->bet * 2);
$this->betLines[] = '';
}
$this->output[] = '.$ucard.'" dealer="'.$dcard.'" state="win" />';
}
if(!empty($this->betLines)) $this->output[] = implode("\r\n",$this->betLines);
$this->output[] = "";
$this->resetVars();
}
function updatePointer(){
mysql_query("UPDATE cardwars SET ponteiro = {$this->pointer} WHERE id = " . $this->game_id);
}
}
?>
dcard = Dealer Card
ucard = Player Card
1/100 is because the values are passed into the game as int, so instead of 2.00 it passes 200.