程序主入口
<?php
include "Table.class.php";
//显示函数
function pre($str){
echo '<pre>';
print_r($str);
echo '</pre>';
}
//创建扑克牌
$c=new Cards();
//初始化玩家数量
$table=new Table(2,$c->Cards);
扑克牌类 Cards.class.php
class Cards{
public $Cards=array();
function __construct()
{
$this->Cards=$this->createCards();
shuffle($this->Cards);
}
private function createCards()
{
$cards=array();
$suit=array("H","S","D","C");
$p=array("T","J","Q","K","A");
for($i=0;$i<count($suit);$i++){
for($j=2;$j<=9;$j++){
$cards[]=$suit[$i].$j;
}
for($k=0;$k<count($p);$k++){
$cards[]=$suit[$i].$p[$k];
}
}
return $cards;
}
}
玩家类 Player.class.php
class Player{
public $score=0;
public $CardInHand=array();
function __construct($cards)
{
$this->getCardInHand($cards);
}
private function getCardInHand($cards){
$randkey=array_rand($cards,2);
$this->CardInHand[]=$cards[$randkey[0]];
$this->CardInHand[]=$cards[$randkey[1]];
return $this->CardInHand;
}
}
牌桌类(核心算法类)Table.class.php
include "Cards.class.php";
include "Player.class.php";
class Table{
public $players=array();
public $tablecards=array();
function __construct($num,$cards)
{
for($i=0;$i<$num;$i++){