-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblackjack.php
More file actions
65 lines (49 loc) · 1.21 KB
/
blackjack.php
File metadata and controls
65 lines (49 loc) · 1.21 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
<?php
class Blackjack {
public $score;
public function __construct($score) {
$this->score = $score;
}
public function initGame(){
$this->score += rand(1, 11) + rand(1, 11);
}
public function hit() {
$this->score += rand(1, 11);
}
public function surrender($player, $dealer){
$player->score = 0;
$dealer->score = 0;
$player->initGame();
$dealer->initGame();
}
};
class Player extends Blackjack {
public $name;
public function __construct($score, $name) {
$this->name = $name;
parent::__construct($score);
}
public function stand($dealer, $player){
return dealerTurn($dealer, $player);
}
};
class Dealer extends Blackjack {
public function __construct($score) {
parent::__construct($score);
}
public function stand(){
}
};
function dealerTurn($dealer, $player){
$dealerScore = $dealer->score;
$playerScore = $player->score;
while ($dealerScore < 18) {
$dealerScore += rand(1, 11);
}
while ($dealerScore >= 18 && $dealerScore < $playerScore){
$dealerScore += rand(1, 11);
}
$dealer->stand();
return $dealerScore;
};
?>