-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblackjack.php
More file actions
85 lines (58 loc) · 1.42 KB
/
blackjack.php
File metadata and controls
85 lines (58 loc) · 1.42 KB
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
<?php
//***********************************
//***********************************
// Function List
//***********************************
//***********************************
// Create a function that totals the value in our hand
function getTotal($hand)
{
$total = 0;
$hold = [];
foreach ($hand as $card)
{
$hold[] = explode('-', $card);
}
foreach ($hold as $card){
switch($card[0]) {
case 'A':
break;
case 'K':
case 'Q':
case 'J':
$total +=10;
break;
default:
$total += (int)$card[0];
break;
}
}
foreach ($hold as $card){
if($card[0] == 'A') {
if(($total + 11) <= 21) {
$total += 11;
} else {
$total += 1;
}
}
}
return $total;
}
// Create a function that shows the value of our hand
function check_value($total) {
if($total > 21) {
$value = "Your hand busted with a value of " . $total . ".\n";
} else {
$value = "The value of your hand is " . $total . ".\n";
}
return $value;
}
//***********************************
//***********************************
// Game Begin
//***********************************
//***********************************
$hand = array('A-H', '10-S');
$total = getTotal($hand);
echo check_value($total);
?>