Style:
Code: Select all
.card {
border-style: solid;
border-width: 1px;
border-color: #eeeeee #000000 #000000 #eeeeee;
width: 3.75em;
height: 5em;
margin: 0.1em;
float: left;
position: relative;
font-size: 24pt;
}
.front {
height: 100%;
width: 100%;
text-align: center;
background-color: #ffffff;
position: absolute;
}
.hearts, .diams {
color: #ff0000;
}
.index {
position: absolute;
left: 0.25em;
font-size: 50%;
font-weight: bold;
}
.a1 { position: absolute; left: 0.75em; top: 0.25em; }
.a2 { position: absolute; left: 0.75em; top: 1.35em; }
.a3 { position: absolute; left: 0.75em; top: 1.85em; }
.a4 { position: absolute; left: 0.75em; top: 2.5em; }
.a5 { position: absolute; left: 0.75em; top: 3.5em; }
.b1 { position: absolute; left: 1.62em; top: 0.75em; }
.b2 { position: absolute; left: 1.62em; top: 0.9em; }
.b3 { position: absolute; left: 1.62em; top: 2em; }
.b4 { position: absolute; left: 1.62em; top: 2.8em; }
.b5 { position: absolute; left: 1.62em; top: 3.25em; }
.c1 { position: absolute; left: 2.45em; top: 0.25em; }
.c2 { position: absolute; left: 2.45em; top: 1.35em; }
.c3 { position: absolute; left: 2.45em; top: 1.85em; }
.c4 { position: absolute; left: 2.45em; top: 2.5em; }
.c5 { position: absolute; left: 2.45em; top: 3.5em; }
.J, .Q, .K {
background-repeat: no-repeat;
background-position: 50% 50%;
height: 100%;
width: 100%;
position: absolute;
}
.A {
font-size: 300%;
position: absolute;
left: 0.3em;
top: 0.2em;
}
.J {
background-image: url(jack.gif);
}
.Q {
background-image: url(queen.gif);
}
.K {
background-image: url(king.gif);
}
Code: Select all
class PlayingCard {
public static $Clubs = "clubs";
public static $Diamonds = "diams";
public static $Hearts = "hearts";
public static $Spades = "spades";
public $suit;
public $rank;
function __construct($suit, $rank)
{
$this->suit = $suit;
$this->rank = $rank;
}
function getRankText()
{
switch ($this->rank)
{
case 1:
return 'A';
break;
case 11:
return 'J';
break;
case 12:
return 'Q';
break;
case 13:
return 'K';
break;
default:
return (string)$this->rank;
}
}
function positionsForRank()
{
switch ($this->rank)
{
case 1:
return array('');
break;
case 2:
return array('b1', 'b5');
break;
case 3:
return array('b1', 'b3', 'b5');
break;
case 4:
return array('a1', 'a5', 'c1', 'c5');
break;
case 5:
return array('a1', 'a5', 'b3', 'c1', 'c5');
break;
case 6:
return array('a1', 'a3', 'a5', 'c1', 'c3', 'c5');
break;
case 7:
return array('a1', 'a3', 'a5', 'b2', 'c1', 'c3', 'c5');
break;
case 8:
return array('a1', 'a3', 'a5', 'b2', 'b4', 'c1', 'c3', 'c5');
break;
case 9:
return array('a1', 'a2', 'a4', 'a5', 'b3', 'c1', 'c2', 'c4', 'c5');
break;
case 10:
return array('a1', 'a2', 'a4', 'a5', 'b2', 'b4', 'c1', 'c2', 'c4', 'c5');
break;
default:
if ($this->rank > 10)
return array('a1', 'c5');
else
return array();
}
}
function getSuitText()
{
return '&' . $this->suit . ';';
}
function getIndexHtml()
{
$output = '<div class="index">'
. $this->getRankText()
. '<br />'
. $this->getSuitText()
. '</div>';
return $output;
}
function getPositionsHtml()
{
$output = '<div class="'
. $this->getRankText()
. '">';
foreach ($this->positionsForRank() as $position)
{
$output .= '<div class=" '
. $position
. '">'
. $this->getSuitText()
. '</div>';
}
$output .= '</div>';
return $output;
}
function getHtml()
{
$output = '<div class="card">'
. '<div class="front '
. $this->suit
. '">'
. $this->getIndexHtml()
. $this->getPositionsHtml()
. '</div>'
. '</div>';
return $output;
}
}Code: Select all
// suits are on static members of the class
// ranks are 1-13 (Ace = 1, King = 13)
$card = new PlayingCard(PlayingCard::$Hearts, 12); // queen of hearts
echo $card->getHtml();http://jenk.co.uk/cards/
http://jenk.co.uk/cards/all.php