-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBet.php
102 lines (82 loc) · 2.49 KB
/
Bet.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
<?php
Class BlackJackBet
{
private $player ;
private $bet ;
private $game ;
private $min ;
private $max;
public function __construct( $game, $player, $bet = null )/*{{{*/
{
$this->game = $game ;
$this->player = $player ;
if ( $bet === null )
{
$bet = min( $game->getMaxBet(), max( $game->getMinBet(), $player->getBet($game) ) );
$bet = min ( $bet, $player->getMoney() ) ;
$bet = round( $bet );
}
if ( $bet > $player->getMoney() ) throw new exception("Player can't afford this round!");
$player->pay ( 0 - $bet );
$this->bet = $bet ;
}/*}}}*/
public function getBet()/*{{{*/
{
return $this->bet ;
}/*}}}*/
public function getPlayer()/*{{{*/
{
return $this->player ;
}/*}}}*/
public function getGame()/*{{{*/
{
return $this->game ;
}/*}}}*/
public function double()/*{{{*/
{
$this->player->pay( 0 - $this->bet );
$this->bet *= 2;
}/*}}}*/
public function surrender()/*{{{*/
{
$this->player->pay( round( $this->bet * 0.05 ) );
$this->bet = 0;
}/*}}}*/
public function dealerBlackJack( $meBlackJack )/*{{{*/
{
$this->payout( $meBlackJack ? 1 : 0 );
}/*}}}*/
public function blackJack( )/*{{{*/
{
$this->payout( 2.5 );
}/*}}}*/
public function dealerBust( $me )/*{{{*/
{
if ( $me > 21 )
$this->payout(0);
else
$this->payout(2);
}/*}}}*/
public function dealer( $me, $dealer )/*{{{*/
{
if ( $me > 21 || $me < $dealer )
$this->payout(0);
elseif ( $me === $dealer )
$this->payout(1);
elseif ( $me > $dealer )
$this->payout(2);
}/*}}}*/
private $paid = false;
private function payout ( $ratio ) /*{{{*/
{
if ( $this->paid ) throw new exception("Double payout!");
if ( $ratio === 0 ) $this->player->lose();
if ( $ratio === 1 ) $this->player->push();
if ( $ratio === 2 ) $this->player->win();
if ( $ratio === 2.5 ) $this->player->blackjack();
$payout = $ratio * $this->bet ;
BlackJackLog::out( BlackJackLog::BET, "Paying player $payout$");
$this->player->pay( round($payout) );
$this->paid = true ;
}/*}}}*/
}