forked from cohenna/php-blackjack
/
browserview.php
160 lines (150 loc) · 4.97 KB
/
browserview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/*
This file is part of 'Nick Cohen's Blackjack.'
Copyright © 2009-2010 Nick Cohen
'Nick Cohen's Blackjack' is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
'Nick Cohen's Blackjack' is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 'Nick Cohen's Blackjack'. If not, see <http://www.gnu.org/licenses/>.
*/
defined('SYSPATH') or die('No direct script access.');
?>
<?php
function displayDealerHand($state, $upcard, $dealerHand, $dealerScore) {
$html = '';
if (State::isActive($state)) {
$html .= getImage($upcard);
}
else {
$html .= getImage($upCard);
$cards = $dealerHand->getCards();
foreach($cards as $card) {
$html .= getImage($card);
}
$html .= '<br><br>';
$html .= 'The dealer has: '.$dealerScore;
}
return $html;
}
?>
<html>
<head>
<title>Blackjack by Nick Cohen</title>
<link href="css/blackjack.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="money">
<?php
$money = $wallet->getMoney();
if($money >= 0) {
$class = 'positive';
}
else {
$class = 'negative';
}
echo '<span>YOUR CASH: </span><span class="'.$class.'">$'.$money.'</span>';
?>
<form method="post" action="index.php">
<?php
$select = 'Wager: ';
if ($wagerEnabled) {
$select .= '<select name="Wager">';
}
else {
$select .= '<select name="Wager" disabled>';
}
for($i = MIN_WAGER; $i <= MAX_WAGER; $i += WAGER_STEP) {
if($i == $wallet->getWager()) {
$select .= '<option selected>';
}
else {
$select .= '<option>';
}
$select .= $i;
$select .= '</option>';
}
$select .= '</select>';
echo $select;
?>
<input type="submit" name="SubmitWager" value="Update"<?php if (!$wagerEnabled) echo 'disabled'; ?>/>
</form>
</div>
<div class="notes">
<h1>Game Notes</h1>
<?php
if ($gameOn) {
if (State::isActive($state)) {
echo "Game is active...";
}
else {
switch ($state) {
case State::USER_BUST:
echo "Sorry, you busted!";
break;
case State::DEALER_WIN:
echo "Sorry, the dealer's hand beats yours!";
break;
case State::DEALER_BUST:
echo "Congratulations, you won! The dealer busted.";
break;
case State::USER_WIN:
echo "Congratulations, you won! Your hand beats the dealer's.";
break;
case State::PUSH:
echo "Push";
break;
case State::USER_BLACKJACK:
echo "Congratulations, you have Blackjack!";
break;
case State::DEALER_BLACKJACK:
echo "Sorry, the dealer has Blackjack!";
break;
default:
echo "Invalid game state.";
break;
}
}
}
else {
echo "Please press Deal to begin playing.";
}
?>
</div>
<div id="dealerhand" class="hand">
<?php
if ($gameOn) {
echo '<h1>Dealer\'s Hand</h1>';
echo displayDealerHand($state, $upcard, $dealerHand, $dealerScore);
}
else {
echo '<h1>Press Deal to Play</h1>';
}
?>
</div>
<div id="userhand" class="hand">
<?php
if ($gameOn) {
echo '<h1>Your Hand</h1>';
$cards = $userHand->getCards();
foreach($cards as $card) {
echo getImage($card);
}
echo '<br><br>You have: '.$userScore.'<br>';
}
?>
</div>
<div class="buttons">
<form method="post" action="index.php">
<input type="submit" name="Deal" value="Deal"<?php if (!$dealEnabled) echo 'disabled'; ?>/><input type="submit" name="Hit" value="Hit"<?php if (!$hitEnabled) echo 'disabled'; ?>/><input type="submit" name="Stand" value="Stand"<?php if (!$standEnabled) echo 'disabled'; ?>/><input type="submit" name="Double" value="Double"<?php if (!$doubleEnabled) echo 'disabled'; ?>/><input type="submit" name="BuyInsurance" value="Buy Insurance"<?php if (!$insuranceEnabled) echo 'disabled'; ?>/><input type="submit" name="DeclineInsurance" value="Decline Insurance" <?php if (!$insuranceEnabled) echo 'disabled'; ?>/>
<br>
<input type="submit" name="Reset" value="Reset Entire Game" />
</form>
</div>
</body>
</html>