GitList
Repositories
Help
Report an Issue
blackjack
Code
Commits
Branches
Tags
Search
Tree:
d7b0224
Branches
Tags
master
blackjack
Objects
Player.php
initial commit
Dev Ghai
commited
d7b0224
at 2014-04-17 16:55:27
Player.php
Blame
History
Raw
<?php /** * User: dev * Date: 3/13/14 * Time: 9:45 AM */ namespace Blackjack\Objects; use Blackjack\Config\Config; require_once 'PlayerBase.php'; class Player extends PlayerBase { public function __construct(Config $config, Hand $hand, $name) { parent::__construct($config, $hand, $name); } public function DoubleDown($handIndex, Card $card) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; //TODO: Double the bet. $isSuccessfullyAdded = $this->hands[$handIndex]->AddCard($card); if($isSuccessfullyAdded) $this->hands[$handIndex]->Lock(); return $isSuccessfullyAdded; } public function CanSplit($handIndex) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; $maxHandsPerPlayer = $this->config->maxHandsPerPlayer; if(count($this->hands) < $maxHandsPerPlayer && $this->hands[$handIndex]->CanSplit()) return true; return false; } public function SplitHand($handIndex, Card $newCard1, Card $newCard2) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; if(!$this->CanSplit($handIndex)) return new Error(E_BJ_CANNOT_SPLIT); list($newHand1, $newHand2) = $this->hands[$handIndex]->Split(); if(get_class($newHand2) == BJ_ERROR_CLASS_NAME) return $newHand2; //Add one card into each hand now. $isSuccessfullyAddedToHand1 = $newHand1->AddCard($newCard1); if($isSuccessfullyAddedToHand1) { $isSuccessfullyAddedToHand2 = $newHand2->AddCard($newCard2); if($isSuccessfullyAddedToHand2) { $this->hands[$handIndex] = $newHand1; array_push($this->hands, $newHand2); } else { return $isSuccessfullyAddedToHand2; } } //Control would reach here with $isSuccessfullyAddedToHand1 as true only if we could add to both //hands successfully. return $isSuccessfullyAddedToHand1; } public function GetHand($handIndex) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; return $this->hands[$handIndex]; } public function DeleteHand($handIndex) { unset($this->hands[$handIndex]); } }