-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathroulette.php
More file actions
114 lines (93 loc) · 3.26 KB
/
Copy pathroulette.php
File metadata and controls
114 lines (93 loc) · 3.26 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
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
<?php
//A Function to spin the roulette wheel
function spin($color){
$num=rand(1, 38);
//they are putting bet on either red or black
if($num==1 || $num==3 || $num==5 || $num==7 || $num==9 || $num==12 || $num==14 || $num==16 || $num==18 || $num==19 || $num==21 || $num==23 || $num==25 || $num==27 || $num==30 || $num==32 || $num==34 || $num==36){
//red
$winningcolor="red";
}else if($num==37 || $num==38){
//green
$winningcolor="green";
}else{
//black
$winningcolor="black";
}
if($color==$winningcolor){
return true;
}else{
return false;
}
}
//If the form is being posted process it below
if(isset($_POST['task'])){
$moneypot = $_POST['moneypot'];
$startingpot = $moneypot;
$wonlast = true;
$base_bet = $_POST['base_bet'];
$maximumbet = $_POST['maximumbet'];
$color = $_POST['color'];
$numspins = $_POST['numspins'];
$result_text = "";
for($i=0;$i<$numspins;$i++){
if($color=="random"){
//choose a random color (red or black)
$myrand = rand(1,2);
$color = "black";
if($myrand==2){
$color = "red";
}
}
if($wonlast){
$current_bet = $base_bet;
}else{
if($current_bet<$maximumbet || $maximumbet==0){
$current_bet = $current_bet*2;
}
}
//make sure there is enough money for bet
if($moneypot<$current_bet){
$result_text .= "not enough money left in your pot to place bet of: ".$current_bet;
break;
}
$result_text .= "your moneypot: ".$moneypot.". your bet: $" . $current_bet . " on ".$color." => ";
if(spin($color)){
$wonlast = true;
$moneypot += $current_bet;
$result_text .= "Winner!<br/>";
}else{
$result_text.= "Loser<br/>";
$wonlast = false;
$moneypot -= $current_bet;
}
}
?>
Starting Money Pot: <?php echo $startingpot; ?><br/>
Base Bet: <?php echo $base_bet; ?><br/>
Maximum Bet: <?php echo $maximumbet; ?><br/>
Color choosen: <?php echo $color; ?><br/>
Number of Spins: <?php echo $numspins ?><br/><br/>
<strong style="font-size:14px">Money after the bets: $<?php echo $moneypot; ?></strong><br/><br/>
Summary of spins: <br/>
<?php echo $result_text; ?>
<?php
}else{
//If the form data has not been submitted just show the form in HTML
?>
<form name="rform" method="post">
Starting Money Pot: <input type="text" value="600" name="moneypot"> *<br/><br/>
Base Bet: <input type="text" value="10" name="base_bet"> *<br/><br/>
Maximum Bet: <input type="text" value="0" name="maximumbet"> (leave at 0 to keep doubling down)<br/><br/>
Color choosen: <select name="color">
<option value="red">Red</option>
<option value="black">Black</option>
<option value="random">Random</option>
</select>
<br/><br/>
Number of Spins to do: <input type="text" value="100" name="numspins"> *<br/><br/>
<input type="hidden" value="spin" name="task">
<input type="submit" value="Spin the wheel!">
</form>
<?php
}
?>