Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <?php
- class Card{
- public $rank;
- public $suit;
- function __construct($rank, $suit){
- $this->rank = $rank;
- $this->suit = $suit;
- }
- }
- class Deck{
- public $card = array();
- function __construct(){
- $ranks = array("Ace",2,3,4,5,6,7,8,9,10,"Jack","Queen","King");
- $suits = array("Clubs","Spades","Hearts","Diamonds");
- foreach($suits as $suit){
- foreach($ranks as $rank){
- $card = new Card($rank, $suit);
- array_push($this->card,$card);
- }
- }
- }
- }
- $deck = new Deck();
- function deal($deck){
- $cardNum = rand(0,52);
- $card = $deck->card[$cardNum];
- echo $card->rank . " of " . $card->suit;
- }
- //Session to save card count
- session_start();
- $cardCount = 0;
- if($_GET['draw']){
- $_SESSION['cardCount'] += intval($_GET['draw']);
- $cardCount = $_SESSION['cardCount'];
- }
- ?>
- <html>
- <head>
- <title>Cards</title>
- <meta charset="UTF-8">
- <link rel="stylesheet" href="style.css" type="text/css">
- </head>
- <body>
- <a id="drawCard" href="index.php?draw=1">Draw Card</a>
- <ul id="output">
- <?php while($cardCount): ?>
- <li><?php deal($deck);?></li>
- <?php $cardCount--; endwhile; ?>
- </ul>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement