Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add images and some index logic

  • Loading branch information...
commit 12cb491290d4e429d45a78d396090bee1a2b7cdb 1 parent 9201468
Michael Kimsal authored
Showing with 361 additions and 5 deletions.
  1. +2 −1  day9/21/bootstrap.php
  2. +26 −0 day9/21/footer.php
  3. +192 −0 day9/21/header.php
  4. BIN  day9/21/images/1.png
  5. BIN  day9/21/images/10.png
  6. BIN  day9/21/images/11.png
  7. BIN  day9/21/images/12.png
  8. BIN  day9/21/images/13.png
  9. BIN  day9/21/images/14.png
  10. BIN  day9/21/images/15.png
  11. BIN  day9/21/images/16.png
  12. BIN  day9/21/images/17.png
  13. BIN  day9/21/images/18.png
  14. BIN  day9/21/images/19.png
  15. BIN  day9/21/images/2.png
  16. BIN  day9/21/images/20.png
  17. BIN  day9/21/images/21.png
  18. BIN  day9/21/images/22.png
  19. BIN  day9/21/images/23.png
  20. BIN  day9/21/images/24.png
  21. BIN  day9/21/images/25.png
  22. BIN  day9/21/images/26.png
  23. BIN  day9/21/images/27.png
  24. BIN  day9/21/images/28.png
  25. BIN  day9/21/images/29.png
  26. BIN  day9/21/images/3.png
  27. BIN  day9/21/images/30.png
  28. BIN  day9/21/images/31.png
  29. BIN  day9/21/images/32.png
  30. BIN  day9/21/images/33.png
  31. BIN  day9/21/images/34.png
  32. BIN  day9/21/images/35.png
  33. BIN  day9/21/images/36.png
  34. BIN  day9/21/images/37.png
  35. BIN  day9/21/images/38.png
  36. BIN  day9/21/images/39.png
  37. BIN  day9/21/images/4.png
  38. BIN  day9/21/images/40.png
  39. BIN  day9/21/images/41.png
  40. BIN  day9/21/images/42.png
  41. BIN  day9/21/images/43.png
  42. BIN  day9/21/images/44.png
  43. BIN  day9/21/images/45.png
  44. BIN  day9/21/images/46.png
  45. BIN  day9/21/images/47.png
  46. BIN  day9/21/images/48.png
  47. BIN  day9/21/images/49.png
  48. BIN  day9/21/images/5.png
  49. BIN  day9/21/images/50.png
  50. BIN  day9/21/images/51.png
  51. BIN  day9/21/images/52.png
  52. BIN  day9/21/images/53.png
  53. BIN  day9/21/images/54.png
  54. BIN  day9/21/images/6.png
  55. BIN  day9/21/images/7.png
  56. BIN  day9/21/images/8.png
  57. BIN  day9/21/images/9.png
  58. BIN  day9/21/images/b1fh.png
  59. BIN  day9/21/images/b1fv.png
  60. BIN  day9/21/images/b1pb.png
  61. BIN  day9/21/images/b1pl.png
  62. BIN  day9/21/images/b1pr.png
  63. BIN  day9/21/images/b1pt.png
  64. BIN  day9/21/images/b2fh.png
  65. BIN  day9/21/images/b2fv.png
  66. BIN  day9/21/images/b2pb.png
  67. BIN  day9/21/images/b2pl.png
  68. BIN  day9/21/images/b2pr.png
  69. BIN  day9/21/images/b2pt.png
  70. +102 −0 day9/21/index.php
  71. +18 −3 day9/21/lib/card.php
  72. +1 −1  day9/21/lib/deck.php
  73. +11 −0 day9/21/lib/player.php
  74. +9 −0 day9/21/tests.php
View
3  day9/21/bootstrap.php
@@ -1,8 +1,8 @@
<?php
+ob_start();
// bootstrap process
// set up anything that needs to be set up here
-session_start();
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BASE_DIR', dirname(__FILE__).DS);
@@ -15,4 +15,5 @@ function __autoload($class)
include($class);
}
+session_start();
View
26 day9/21/footer.php
@@ -0,0 +1,26 @@
+</div>
+ <div id="ft">
+
+<div class="col1">
+copyright 2010...
+</div>
+
+<div class="col1">
+ <h2>about</h2>
+ <ul>
+ <li>link1</li>
+ <li>link2</li>
+ <li>link3</li>
+ </ul>
+
+</div>
+
+<div class="col1">
+</div>
+
+<div class="col1">
+</div>
+
+ </div>
+</body>
+</html>
View
192 day9/21/header.php
@@ -0,0 +1,192 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>21/pontoon/blackjack</title>
+ <link rel="stylesheet" href="http://yui.yahooapis.com/3.2.0/build/cssreset/reset.css" type="text/css">
+ <link rel="stylesheet" href="http://yui.yahooapis.com/3.2.0/build/cssfonts/fonts.css" type="text/css">
+ <link rel="stylesheet" href="http://yui.yahooapis.com/3.2.0/build/cssgrids/grids.css" type="text/css">
+
+<style>
+html, body {
+height: 100%;
+}
+body {
+ background-color: #f8f8f8;
+}
+#doc {
+background-color: #f8f8f8;
+margin:auto; /* center in viewport */
+width: 100%; /* fix page width */
+font-family: helvetica,arial,freesans,clean,sans-serif;
+font-size: 24px;
+}
+
+/* arbitrary content styling */
+#hd {
+padding-top: 8px;
+padding-left: 20px;
+height: 50px;
+background-color: #223;
+}
+#hd h1 {
+color: #f9f9f9;
+font-size: 32px;
+float:left;
+}
+#hd h1 a {
+ text-decoration:none;
+ color: #f9f9f9;
+ font-size: 32px;
+ float:left;
+}
+
+#hd .menu {
+ float:right;
+color: #f9f9f9;
+font-size: 20px;
+padding-top: 5px;
+padding-right: 20px;
+}
+.menu li {
+-webkit-border-radius: 8px;
+-moz-border-radius: 8px;
+border-radius: 8px;
+list-style-type: none;
+display: inline;
+float:left;
+margin-right: 80px;
+padding: 5px;
+}
+
+
+.menu li a {
+ color: #f9f9f9;
+ text-decoration:none;
+}
+
+
+.menu li:hover {
+ background-color: #f9f9f9;
+ color: #223;
+}
+.menu li:hover a {
+ background-color: #f9f9f9;
+ color: #223;
+}
+.content {
+ background-color: #f8f8f8;
+}
+#ft {
+margin-top: 50px;
+background-color: #f8f8f8;
+background-image: url("gradient.png");
+background-repeat: repeat-x;
+height: 160px;
+padding-left: 40px;
+padding-top:20px;
+}
+#ft li {
+ font-size: 16px;
+}
+#ft h2 {
+ text-shadow: 1px 1px #fefefe;
+}
+
+
+#ft .col1 {
+
+ width: 24%;
+float:left;
+}
+#ft .col2 {
+
+ width: 24%;
+float:left;
+}
+#ft .col3 {
+
+ width: 24%;
+float:left;
+}
+#ft .col4 {
+ width: 24%;
+float:left;
+
+}
+
+
+#main {
+ margin: 0 auto;
+ margin-top: 30px;
+ width: 960px;
+ border: thin solid #f7f7f6;
+overflow:auto;
+-webkit-border-radius: 8px;
+-moz-border-radius: 8px;
+border-radius: 8px;
+ padding: 10px;
+
+}
+#main h1 {
+ font-size: 42px;
+ text-align:center;
+ font-weight: bold;
+}
+#main #left {
+ float:left;
+ width: 60%;
+}
+#main #right{
+ float:right;
+ width: 40%;
+ text-align:center;
+}
+#right h2 {
+ text-align:center;
+}
+
+#main li {
+ padding-top: 10px;
+ margin-left: 40px;
+ font-size: 32px;
+}
+
+#pricepoints li {
+ margin-left: inherit;
+ text-align:center;
+}
+
+.cards {
+ width: 380px;
+}
+.card {
+float:left;
+margin-right: 20px;
+}
+#message {
+ overflow:none;
+ width:70%;
+ margin: 0 auto;
+ text-align:center;
+ font-size: 24px;
+ background-color: #d66;
+ color: #f0f0f0;
+
+}
+</style>
+
+
+</head>
+<body id="doc">
+ <div id="hd">
+ <h1><a href="index.php">21/pontoon/blackjack</a></h1>
+<div class="menu">
+<ul>
+<li><a href="?restart=y">restart</a></li>
+</ul>
+</div>
+ </div>
+
+ <div class="content">
+
View
BIN  day9/21/images/1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/13.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/14.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/15.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/17.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/18.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/19.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/21.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/22.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/23.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/24.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/25.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/26.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/27.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/28.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/29.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/30.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/31.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  day9/21/images/32.png
Diff not rendered
View
BIN  day9/21/images/33.png
Diff not rendered
View
BIN  day9/21/images/34.png
Diff not rendered
View
BIN  day9/21/images/35.png
Diff not rendered
View
BIN  day9/21/images/36.png
Diff not rendered
View
BIN  day9/21/images/37.png
Diff not rendered
View
BIN  day9/21/images/38.png
Diff not rendered
View
BIN  day9/21/images/39.png
Diff not rendered
View
BIN  day9/21/images/4.png
Diff not rendered
View
BIN  day9/21/images/40.png
Diff not rendered
View
BIN  day9/21/images/41.png
Diff not rendered
View
BIN  day9/21/images/42.png
Diff not rendered
View
BIN  day9/21/images/43.png
Diff not rendered
View
BIN  day9/21/images/44.png
Diff not rendered
View
BIN  day9/21/images/45.png
Diff not rendered
View
BIN  day9/21/images/46.png
Diff not rendered
View
BIN  day9/21/images/47.png
Diff not rendered
View
BIN  day9/21/images/48.png
Diff not rendered
View
BIN  day9/21/images/49.png
Diff not rendered
View
BIN  day9/21/images/5.png
Diff not rendered
View
BIN  day9/21/images/50.png
Diff not rendered
View
BIN  day9/21/images/51.png
Diff not rendered
View
BIN  day9/21/images/52.png
Diff not rendered
View
BIN  day9/21/images/53.png
Diff not rendered
View
BIN  day9/21/images/54.png
Diff not rendered
View
BIN  day9/21/images/6.png
Diff not rendered
View
BIN  day9/21/images/7.png
Diff not rendered
View
BIN  day9/21/images/8.png
Diff not rendered
View
BIN  day9/21/images/9.png
Diff not rendered
View
BIN  day9/21/images/b1fh.png
Diff not rendered
View
BIN  day9/21/images/b1fv.png
Diff not rendered
View
BIN  day9/21/images/b1pb.png
Diff not rendered
View
BIN  day9/21/images/b1pl.png
Diff not rendered
View
BIN  day9/21/images/b1pr.png
Diff not rendered
View
BIN  day9/21/images/b1pt.png
Diff not rendered
View
BIN  day9/21/images/b2fh.png
Diff not rendered
View
BIN  day9/21/images/b2fv.png
Diff not rendered
View
BIN  day9/21/images/b2pb.png
Diff not rendered
View
BIN  day9/21/images/b2pl.png
Diff not rendered
View
BIN  day9/21/images/b2pr.png
Diff not rendered
View
BIN  day9/21/images/b2pt.png
Diff not rendered
View
102 day9/21/index.php
@@ -0,0 +1,102 @@
+<?php include("bootstrap.php");?>
+<?php include("header.php");?>
+
+<?php
+if($_GET['restart']=='y')
+{
+ session_destroy();
+ header("Location: ./");
+ die();
+}
+
+if($_SESSION['inplay']=='')
+{
+ $_SESSION['inplay'] = 'y';
+ $deck = new Deck();
+ $_SESSION['deck'] = $deck;
+ $_SESSION['player'] = new Player("player");
+ $_SESSION['dealer'] = new Player("dealer");
+ $_SESSION['player']->takeCard($deck);
+ $_SESSION['dealer']->takeCard($deck);
+ $_SESSION['player']->takeCard($deck);
+ $_SESSION['dealer']->takeCard($deck);
+ $player = $_SESSION['player'];
+ $dealer = $_SESSION['dealer'];
+ $deck = $_SESSION['deck'];
+
+} else {
+ $player = $_SESSION['player'];
+ $dealer = $_SESSION['dealer'];
+ $deck = $_SESSION['deck'];
+
+ if($_GET['hit']=='y')
+ {
+ $player->takeCard($deck);
+ }
+
+ if($_GET['hit']=='y' || $_GET['stand']=='y')
+ {
+ if($dealer->getHandValue()<21)
+ {
+ $dealer->takeCard($deck);
+ }
+ }
+
+ if($dealer->isBust())
+ {
+ $message = "Dealer went bust!";
+ $_SESSION['inplay']='';
+ } else {
+ if($player->isBust())
+ {
+ $message = "YOU went bust!";
+ $_SESSION['inplay']='';
+ }
+ }
+
+
+
+}
+?>
+
+
+<div id="main">
+ <div id="left">
+ <h1>
+<?=$player->name;?>
+ </h1>
+ <div class="cards">
+<?=$player->renderHand();?>
+ </div>
+<div style="clear:both;"></div>
+<h2>Hand: <?=$player->getHandValue();?></h2>
+<?php
+if(!$player->isBust() && $_SESSION['inplay']=='y') {
+?>
+<a href="?hit=y">HIT ME</a> |
+<a href="?stand=y">STAND</a>
+<?php
+}
+?>
+ </div>
+
+ <div id="right">
+ <h1>
+<?=$dealer->name;?>
+ </h1>
+ <div class="cards">
+<?=$dealer->renderHand();?>
+ </div>
+
+ </div>
+</div>
+
+<div id="message">
+<?=$message;?>
+</div>
+
+
+
+
+
+<?php include("footer.php");?>
View
21 day9/21/lib/card.php
@@ -17,22 +17,37 @@ public function getValue()
return $values[$this->value];
}
+ public function getImageNumber()
+ {
+ list($suits, $values) = self::getSuitsValues();
+ $suitPos = array_search($this->suit, array_reverse(array_keys($suits)));
+ $valuePos = array_search($this->value, array_reverse(array_keys($values)));
+ $num = ($valuePos*4) + ($suitPos)+1;
+ return $num;
+ }
+
+ public function getImage()
+ {
+ return "images/".$this->getImageNumber().".png";
+ }
+
static function getSuitsValues()
{
static $suits;
static $values;
if($suits=='')
{
- $suits = array("D"=>"Diamonds","H"=>"Hearts","C"=>"Clubs","S"=>"Spades");
- $values["A"] = "Ace";
+ $suits = array("D"=>"Diamonds","H"=>"Hearts","S"=>"Spades","C"=>"Clubs");
for($x=2; $x<=10; $x++)
{
$values[$x] = $x;
}
$values["J"] = 10;
- $values["K"] = 10;
$values["Q"] = 10;
+ $values["K"] = 10;
+ $values["A"] = "Ace";
}
return array($suits, $values);
}
+
}
View
2  day9/21/lib/deck.php
@@ -16,7 +16,7 @@ public function initDeck()
foreach($suits as $suit) {
foreach($values as $k=>$v){
- $cards[] = new Card($suit, $value);
+ $cards[] = new Card($suit, $v);
}
}
shuffle($cards);
View
11 day9/21/lib/player.php
@@ -68,4 +68,15 @@ public function isBust()
return false;
}
+
+ public function renderHand()
+ {
+ foreach($this->hand as $c)
+ {
+ echo "<div class='card'>\n";
+ echo "<img src='".$c->getImage()."'/>\n";
+ echo "</div>\n";
+ }
+
+ }
}
View
9 day9/21/tests.php
@@ -4,6 +4,7 @@
// test 1
+
$deck = new Deck();
assert(count($deck->getCards())==52);
@@ -52,3 +53,11 @@
$p->giveCard(new Card("S","J"));
assert($p->getHandValue()==22);
assert($p->isBust());
+
+
+$c = new Card("D","9");
+assert($c->getImageNumber()==24);
+$c = new Card("C","8");
+assert($c->getImageNumber()==25);
+$c = new Card("C","9");
+assert($c->getImageNumber()==21);
Please sign in to comment.
Something went wrong with that request. Please try again.