GitList
Repositories
Help
Report an Issue
blackjack
Code
Commits
Branches
Tags
Search
Tree:
d7b0224
Branches
Tags
master
blackjack
Objects
PlayerBase.php
initial commit
Dev Ghai
commited
d7b0224
at 2014-04-17 16:55:27
PlayerBase.php
Blame
History
Raw
<?php /** * User: dev * Date: 3/16/14 * Time: 10:52 PM */ namespace Blackjack\Objects; require_once 'Config/Config.php'; require_once 'Hand.php'; require_once 'Card.php'; use Blackjack\Config\Config; class PlayerBase { //This needs to be public to allow json_encode to serialize it. public $hands = array(); protected $name = ''; protected $config; public function __construct(Config $config, Hand $hand, $name) { $this->name = $name; $this->config = $config; array_push($this->hands, $hand); } public function GetName() { return $this->name; } public function GetHands() { return $this->hands; } protected function ValidateHandIndex($index) { //Hands can be deleted too when it has lost. if(!array_key_exists($index, $this->hands)) return new Error(E_BJ_HAND_BAD_INDEX); return true; } public function Hit($handIndex, Card $card) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; return $this->hands[$handIndex]->AddCard($card); } }