Simple example of php poker code

WBOY
Release: 2016-07-25 08:56:55
Original
3071 people have browsed it
This article shares a piece of php code that can simulate the gameplay of poker. Friends in need can refer to it.

php poker code, as follows:

<?php
/*** 
*
* A simple class to cut a deck of cards
* @version    CVS: $Id:$
* @since      Class available since Release 1.0.0

* Example use
*
* $cards = new cards;
* echo $cards->cut();
* www: jbxue.com
*/


class cards{

/**
*
* Declare our deck variable 
*
*/
private $deck;

/**
*
* Constructor.. duh!
*
*/
function __construct(){

  /*** set the deck array variable ***/
  $this->deck=$this->setDeck();
}

/**
*
* Function set Deck
*
* @access private
*
* @return array
*
*/
private function setDeck(){
return array("ah", "ac", "ad", "as",
               "2h", "2c", "2d", "2s",
               "3h", "3c", "3d", "3s",
               "4h", "4c", "4d", "4s",
               "5h", "5c", "5d", "5s",
               "6h", "6c", "6d", "6s",
               "7h", "7c", "7d", "7s",
               "8h", "8c", "8d", "8s",
               "9h", "9c", "9d", "9s",
               "th", "tc", "td", "ts",
               "jh", "jc", "jd", "js",
               "qh", "qc", "qd", "qs",
               "kh", "kc", "kd", "ks");
}

/**
*
* Function get Key get the array key
*
* @access private
*
* @return INT
*
*/
private function getKey(){
  shuffle($this->deck);
  return array_rand($this->deck);
}

/**
*
* @Function cut, get the value of the array key
*
* @access public
*
* @return string
*
*/
public function cut(){
  return $this->deck[$this->getKey()];
}

} /*** end of class ***/


$cards = new cards;
echo $cards->cut();

?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!