Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( 27e319...99d485 )
by Dan
04:07
created

get_value()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
c 0
b 0
f 0
nc 12
nop 1
dl 0
loc 20
rs 9.2222
1
<?php declare(strict_types=1);
2
3
// blackjack
4
$message = '';
5
6
function create_card($card, $show) {
7
	//only display what the card really is if they want to
8
	$card_height = 100;
9
	$card_width = 125;
10
11
	$suit = $card->getSuitName();
12
	$card_name = $card->getRankName();
13
14
	$return = ('<td>');
15
	//lets try and echo cards
16
	$return .= ('<table style="border:1px solid green"><tr><td><table><tr><td valign=top class="left" height=' . $card_height . ' width=' . $card_width . '>');
17
	if ($show) {
18
		$return .= ('<h1>' . $card_name . '<img src="images/' . $suit . '.gif"></h1></td></tr>');
19
	} else {
20
		$return .= ('</td></tr>');
21
	}
22
	$return .= ('<tr><td valign=bottom class="right" height=' . $card_height . ' width=' . $card_width . '>');
23
	if ($show) {
24
		$return .= ('<h1><img src="images/' . $suit . '.gif">' . $card_name . '</h1></td></tr></table>');
25
	} else {
26
		$return .= ('</td></tr></table>');
27
	}
28
	$return .= ('</td></tr></table></td>');
29
	return $return;
30
}
31
32
function check_for_win($dealerHand, $playerHand) {
33
	$comp = $dealerHand->getValue();
34
	$play = $playerHand->getValue();
35
36
	//does the player win
37
	if ($playerHand->hasBlackjack()) {
38
		return 'bj';
39
	} elseif ($play > $comp && $comp <= 21 && $play <= 21) {
40
		return 'yes';
41
	} elseif ($play == $comp && $comp <= 21) {
42
		return 'tie';
43
	} elseif ($comp > 21) {
44
		return 'yes';
45
	} else {
46
		return 'no';
47
	}
48
}
49
50
$deck = $var['deck'] ?? new \Blackjack\Deck();
51
$playerHand = $var['player_hand'] ?? new \Blackjack\Hand();
52
$dealerHand = $var['dealer_hand'] ?? new \Blackjack\Hand();
53
54
if (isset($var['player_does'])) {
55
	$do = $var['player_does'];
56
} else {
57
	$do = 'nothing';
58
}
59
//new game if $do == nothing
60
if ($do == 'nothing') {
61
	$bet = Request::getVarInt('bet');
62
	if ($player->getCredits() < $bet) {
63
		create_error('Not even enough to play BlackJack...you need to trade!');
64
	}
65
	if ($bet == 0) {
66
		create_error('We don\'t want you here if you don\'t want to play with cash!');
67
	}
68
	if ($bet > 100 && $player->getNewbieTurns() > 0) {
69
		create_error('Sorry.  According to Galactic Laws we can only play with up to 100 credits while under newbie protection.');
70
	}
71
	if ($bet > 10000) {
72
		create_error('Sorry.  According to Galactic Laws we can only play with up to 10,000 credits');
73
	}
74
	if ($bet < 0) {
75
		create_error('Yeah...we are gonna give you money to play us! GREAT IDEA!!');
76
	}
77
	$player->decreaseCredits($bet);
78
79
	//first we deal some cards...player,ai,player,ai
80
	$playerHand->drawCard($deck);
81
	$dealerHand->drawCard($deck);
82
	$playerHand->drawCard($deck);
83
	$dealerHand->drawCard($deck);
84
}
85
86
if (isset($var['bet'])) {
87
	$bet = $var['bet'];
88
}
89
90
if ($do == 'HIT') {
91
	$playerHand->drawCard($deck);
92
}
93
94
//only display if we wont display later..
95
if ($do != 'STAY' && $playerHand->getValue() != 21) {
96
	//heres the AIs cards
97
	$i = 1;
98
	if ($dealerHand->hasBlackjack() ||
99
	    ($playerHand->getValue() > 21 && $dealerHand->getValue() <= 21)) {
100
		$message .= ('<h1 class="red center">Bank Wins</h1>');
101
	}
102
	$message .= ('<div class="center">Bank\'s Cards are</div><br /><table class="center"><tr>');
103
	foreach ($dealerHand->getCards() as $key => $card) {
104
		if ($key == 0) {
105
			//do we need a new row?
106
			if ($i == 4 || $i == 7 || $i == 10) {
107
				$message .= ('</tr><tr>');
108
			}
109
			$message .= create_card($card, TRUE);
110
			//get curr val of this card...for the at least part
111
			$ai_val = $card->getValue();
112
		} else {
113
			//lets try and echo cards
114
			//new row?
115
			if ($i == 4 || $i == 7 || $i == 10) {
116
				$message .= ('</tr><tr>');
117
			}
118
			if ($dealerHand->getValue() == 21 || $playerHand->getValue() >= 21) {
119
				$message .= create_card($card, TRUE);
120
			} else {
121
				$message .= create_card($card, FALSE);
122
			}
123
		}
124
		$i++;
125
	}
126
127
	$message .= ('</tr></table>');
128
	if ($dealerHand->hasBlackjack()) {
129
		$message .= ('<div class="center">Bank has BLACKJACK!</div><br />');
130
		$win = 'no';
131
	} elseif ($playerHand->getValue() >= 21) {
132
		$message .= ('<div class="center">Bank has ' . $dealerHand->getValue() . '</div><br />');
133
	} else {
134
		$message .= ('<div class="center">Bank has at least ' . $ai_val . '</div><br />');
135
	}
136
}
137
138
if ($do == 'STAY' || $playerHand->getValue() == 21) {
139
	//heres the Banks cards
140
	$i = 1;
141
142
	if (!$playerHand->hasBlackjack()) {
143
		while ($dealerHand->getValue() < 17) {
144
			$dealerHand->drawCard($deck);
145
		}
146
	}
147
	$win = check_for_win($dealerHand, $playerHand);
148
	if ($win == 'yes' || $win == 'bj') {
149
		$message .= ('<h1 class="green center">You Win</h1>');
150
	} elseif ($win == 'tie') {
151
		$message .= ('<h1 class="yellow center">TIE Game</h1>');
152
	} else {
153
		$message .= ('<h1 class="red center">Bank Wins</h1>');
154
	}
155
	$message .= ('<div class="center">Bank\'s Cards are</div><br /><table class="center"><tr>');
156
	foreach ($dealerHand->getCards() as $key => $card) {
157
		//now row?
158
		if ($i == 4 || $i == 7 || $i == 10) {
159
			$message .= ('</tr><tr>');
160
		}
161
		$message .= create_card($card, TRUE);
162
		$i++;
163
	}
164
	$message .= ('</tr></table><div class="center">');
165
	if ($dealerHand->getValue() > 21) {
166
		$message .= ('Bank <span class="red"><b>BUSTED</b></span><br /><br />');
167
	} else {
168
		$message .= ('Bank has ' . $dealerHand->getValue() . '<br /><br />');
169
	}
170
	$message .= ('</div>');
171
}
172
$message .= ('<hr style="border:1px solid green;width:50%" noshade>');
173
$i = 1;
174
175
$val1 = $playerHand->getValue();
176
177
$message .= ('<div class="center">Your Cards are</div><br /><table class="center"><tr>');
178
foreach ($playerHand->getCards() as $key => $card) {
179
	if ($i == 4 || $i == 7 || $i == 10) {
180
		$message .= ('</tr><tr>');
181
	}
182
	$message .= create_card($card, TRUE);
183
	$i++;
184
}
185
$message .= ('</tr></table>');
186
187
if ($playerHand->hasBlackjack()) {
188
	$message .= '<div class="center">You have BLACKJACK!</div><br />';
189
} else {
190
	$message .= ('<div class="center">You have a total of ' . $playerHand->getValue() . ' </div><br />');
191
}
192
193
//check for win
194
if ($do == 'STAY') {
195
	$win = check_for_win($dealerHand, $playerHand);
196
}
197
198
$container = create_container('bar_gambling_processing.php');
199
transfer('LocationID');
200
$container['bet'] = $bet;
201
202
$message .= ('<div class="center">');
203
if ($playerHand->getValue() > 21) {
204
	$message .= ('You have <span class="red"><b>BUSTED</b></span>');
205
	$player->increaseHOF($bet, array('Blackjack', 'Money', 'Lost'), HOF_PUBLIC);
206
	$player->increaseHOF(1, array('Blackjack', 'Results', 'Lost'), HOF_PUBLIC);
207
	$message .= '<p><a class="submitStyle" href="' . SmrSession::getNewHREF($container) . '">Play Some More ($' . $bet . ')</a></p>';
208
	$message .= ('</div>');
209
} elseif (!isset($win) && $playerHand->getValue() < 21) {
210
	$container['deck'] = $deck;
211
	$container['player_hand'] = $playerHand;
212
	$container['player_does'] = 'HIT';
213
	$container['dealer_hand'] = $dealerHand;
214
	$message .= '<form method="POST" action="' . SmrSession::getNewHREF($container) . '">';
215
	$message .= '<input type="submit" name="action" value="HIT" />';
216
	$message .= ('<br /><small><br /></small></form>');
217
	$container['player_does'] = 'STAY';
218
	$message .= '<form method="POST" action="' . SmrSession::getNewHREF($container) . '">';
219
	$message .= '<input type="submit" name="action" value="STAY" />';
220
	$message .= ('</form></div>');
221
} elseif (isset($win)) {
222
	//we have a winner...but who!
223
	if ($win == 'bj') {
224
		$winnings = IFloor($bet * 2.5);
225
		$player->increaseCredits($winnings);
226
		$stat = $winnings - $bet;
227
		$player->increaseHOF($stat, array('Blackjack', 'Money', 'Won'), HOF_PUBLIC);
228
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Won'), HOF_PUBLIC);
229
		$message .= ('You have won $' . number_format($winnings) . ' credits!');
230
	} elseif ($win == 'yes') {
231
		$winnings = $bet * 2;
232
		$player->increaseCredits($winnings);
233
		$stat = $winnings - $bet;
234
		$player->increaseHOF($stat, array('Blackjack', 'Money', 'Won'), HOF_PUBLIC);
235
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Won'), HOF_PUBLIC);
236
		$message .= ('You have won $' . number_format($winnings) . ' credits!');
237
	} elseif ($win == 'tie') {
238
		$player->increaseCredits($bet);
239
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Draw'), HOF_PUBLIC);
240
		$message .= ('You have won back your $' . number_format($bet) . ' credits.');
241
	} else {
242
		$player->increaseHOF($bet, array('Blackjack', 'Money', 'Lost'), HOF_PUBLIC);
243
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Lost'), HOF_PUBLIC);
244
	}
245
	$message .= '<p><a class="submitStyle" href="' . SmrSession::getNewHREF($container) . '">Play Some More ($' . $bet . ')</a></p>';
246
	$message .= ('</div>');
247
} elseif ($playerHand->getValue() == 21) {
248
	if ($dealerHand->getValue() != 21) {
249
		if ($playerHand->getNumCards() == 2) {
250
			$multiplier = 2.5;
251
		} else {
252
			$multiplier = 2;
253
		}
254
		$winnings = IFloor($bet * $multiplier);
255
		$player->increaseCredits($winnings);
256
		$stat = $winnings - $bet;
257
		$player->increaseHOF($stat, array('Blackjack', 'Money', 'Win'), HOF_PUBLIC);
258
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Win'), HOF_PUBLIC);
259
		$message .= ('You have won $' . number_format($winnings) . ' credits!');
260
	} elseif ($dealerHand->getNumCards() > 2) {
261
		$winnings = $bet;
262
		$player->increaseCredits($winnings);
263
		$stat = $winnings - $bet;
264
		$player->increaseHOF($stat, array('Blackjack', 'Money', 'Win'), HOF_PUBLIC);
265
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Win'), HOF_PUBLIC);
266
		$message .= ('You have won back your $' . number_format($winnings) . ' credits!');
267
	} else {
268
		//AI has BJ already...sorry
269
		$player->increaseHOF($bet, array('Blackjack', 'Money', 'Lost'), HOF_PUBLIC);
270
		$player->increaseHOF(1, array('Blackjack', 'Results', 'Lost'), HOF_PUBLIC);
271
	}
272
	$message .= '<p><a class="submitStyle" href="' . SmrSession::getNewHREF($container) . '">Play Some More ($' . $bet . ')</a></p>';
273
	$message .= ('</div>');
274
}
275
276
$player->update();
277
$container = create_container('skeleton.php', 'bar_gambling_bet.php');
278
transfer('LocationID');
279
$container['message'] = $message;
280
$container['AllowAjax'] = false;
281
forward($container);
282