yahtzee
Code (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
session_start();
include("mysql_connect.php");
if(empty($_POST)){
//geld inzetten(eerste scherm)
//
//
echo("Hoeveel geld wil je inzetten<form action=".$_SERVER['PHP_SELF']." method=post>");
echo("<input type=hidden value=x name=1><input type=text name=inzet><input type=submit value=start></form>");
}elseif(isset($_POST["1"])){
//stenen kieze(eerste keer)
//
//
if(($_POST["inzet"]<100)){
die("Ongeldig bedrag.<br><a href=yahtzee.php>Terug</a>");
}
$inzet_yahtzee=$_POST["inzet"];
session_register("inzet_yahtzee");
echo("<form action=".$_SERVER['PHP_SELF']." method=post><table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}
echo("</tr><tr>");
for($i=1; $i<=5; $i++){
echo("<td><input type=checkbox name=\"keuze$i\" value=$rand[$i]></td>");
}
echo("</tr></table><input type=hidden value=x name=2><input type=submit value=Doorgaan></form><p>Kies dobbelstenen, eerste keer");
}elseif(isset($_POST["2"])){
//stenen kieze(tweede keer)
//
//
echo("<form action=".$_SERVER['PHP_SELF']." method=post><table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
if(@!isset($_POST["keuze$i"])){
$gekozen[$i]=false;
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}else{
$gekozen[$i]=true;
$rand[$i]=$_POST["keuze$i"];
echo("<td>".$rand[$i]."</td>");
}
}
echo("</tr><tr>");
for($i=1; $i<=5; $i++){
$x="";
if($gekozen[$i]==true){ $x="CHECKED"; }
echo("<td><input type=checkbox name=\"keuze$i\" value=\"$rand[$i]\" $x></td>");
}
echo("</tr></table><input type=hidden value=x name=uitslag><input type=submit value=Doorgaan></form><p>Kies uw stenen, laatste keer");
}elseif(isset($_POST["uitslag"])){
//uitslag
//
//
echo("<table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
if(@!isset($_POST["keuze$i"])){
$gekozen[$i]=false;
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}else{
$gekozen[$i]=true;
$rand[$i]=$_POST["keuze$i"];
echo("<td>".$rand[$i]."</td>");
}
}
$a1=0; $a2=0; $a3=0; $a4=0; $a5=0; $a6=0;
for($i=1; $i<=5; $i++){
if($rand[$i]==1){
$a1=$a1+1;
}elseif($rand[$i]==2){
$a2=$a2+1;
}elseif($rand[$i]==3){
$a3=$a3+1;
}elseif($rand[$i]==4){
$a4=$a4+1;
}elseif($rand[$i]==5){
$a5=$a5+1;
}elseif($rand[$i]==6){
$a6=$a6+1;
}
}
if($a1==3){ $won[0]="three_of_a_kind"; }
if($a1==4){ $won[1]="four_of_a_kind"; }
if($a1==5){ $won[2]="yahtzee"; }
if($a2==3){ $won[0]="three_of_a_kind"; }
if($a2==4){ $won[1]="four_of_a_kind"; }
if($a2==5){ $won[2]="yahtzee"; }
if($a3==3){ $won[0]="three_of_a_kind"; }
if($a3==4){ $won[1]="four_of_a_kind"; }
if($a3==5){ $won[2]="yahtzee"; }
if($a4==3){ $won[0]="three_of_a_kind"; }
if($a4==4){ $won[1]="four_of_a_kind"; }
if($a4==5){ $won[2]="yahtzee"; }
if($a5==3){ $won[0]="three_of_a_kind"; }
if($a5==4){ $won[1]="four_of_a_kind"; }
if($a5==5){ $won[2]="yahtzee"; }
if($a6==3){ $won[0]="three_of_a_kind"; }
if($a6==4){ $won[1]="four_of_a_kind"; }
if($a6==5){ $won[2]="yahtzee"; }
if(($a1==1) AND ($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1)){ $won[3]="large_strait"; }
if(($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1) AND ($a6==1)){ $won[3]="large_strait"; }
if(isset($won[0]) AND(($a1==2)OR($a2==2)OR($a3==2)OR($a4==2)OR($a5==2)OR($a6==2))){
$won[4]="full_house";
unset ($won[0]);
}
echo("</tr></table>");
for($i=0; $i<=5; $i++){
if(isset($won[$i])){
$gewonnen=$i;
}
}
if(isset($won[0])){ $winst=$_SESSION["inzet_yahtzee"]; }//je geld terug
elseif(isset($won[1])){ $winst=$_SESSION["inzet_yahtzee"]/100*180; }//80% winst
elseif(isset($won[2])){ $winst=$_SESSION["inzet_yahtzee"]/100*300; }//200% winst
elseif(isset($won[3])){ $winst=$_SESSION["inzet_yahtzee"]/100*150; }//50% winst
elseif(isset($won[4])){ $winst=$_SESSION["inzet_yahtzee"]/100*130; }//30% winst
if(!isset($gewonnen)){
echo "Helaas, je hebt niks gewonnen";
}else{
echo "Je hebt ".$won[$gewonnen];
echo "<br>Je winst is ".$winst;
}
echo("<br><a href=yahtzee.php>Nog een keertje</a>");
}
?>
session_start();
include("mysql_connect.php");
if(empty($_POST)){
//geld inzetten(eerste scherm)
//
//
echo("Hoeveel geld wil je inzetten<form action=".$_SERVER['PHP_SELF']." method=post>");
echo("<input type=hidden value=x name=1><input type=text name=inzet><input type=submit value=start></form>");
}elseif(isset($_POST["1"])){
//stenen kieze(eerste keer)
//
//
if(($_POST["inzet"]<100)){
die("Ongeldig bedrag.<br><a href=yahtzee.php>Terug</a>");
}
$inzet_yahtzee=$_POST["inzet"];
session_register("inzet_yahtzee");
echo("<form action=".$_SERVER['PHP_SELF']." method=post><table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}
echo("</tr><tr>");
for($i=1; $i<=5; $i++){
echo("<td><input type=checkbox name=\"keuze$i\" value=$rand[$i]></td>");
}
echo("</tr></table><input type=hidden value=x name=2><input type=submit value=Doorgaan></form><p>Kies dobbelstenen, eerste keer");
}elseif(isset($_POST["2"])){
//stenen kieze(tweede keer)
//
//
echo("<form action=".$_SERVER['PHP_SELF']." method=post><table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
if(@!isset($_POST["keuze$i"])){
$gekozen[$i]=false;
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}else{
$gekozen[$i]=true;
$rand[$i]=$_POST["keuze$i"];
echo("<td>".$rand[$i]."</td>");
}
}
echo("</tr><tr>");
for($i=1; $i<=5; $i++){
$x="";
if($gekozen[$i]==true){ $x="CHECKED"; }
echo("<td><input type=checkbox name=\"keuze$i\" value=\"$rand[$i]\" $x></td>");
}
echo("</tr></table><input type=hidden value=x name=uitslag><input type=submit value=Doorgaan></form><p>Kies uw stenen, laatste keer");
}elseif(isset($_POST["uitslag"])){
//uitslag
//
//
echo("<table border=1 bordercolor=black><tr>");
for($i=1; $i<=5; $i++){
if(@!isset($_POST["keuze$i"])){
$gekozen[$i]=false;
$rand[$i]=mt_rand(1,6);
echo("<td>".$rand[$i]."</td>");
}else{
$gekozen[$i]=true;
$rand[$i]=$_POST["keuze$i"];
echo("<td>".$rand[$i]."</td>");
}
}
$a1=0; $a2=0; $a3=0; $a4=0; $a5=0; $a6=0;
for($i=1; $i<=5; $i++){
if($rand[$i]==1){
$a1=$a1+1;
}elseif($rand[$i]==2){
$a2=$a2+1;
}elseif($rand[$i]==3){
$a3=$a3+1;
}elseif($rand[$i]==4){
$a4=$a4+1;
}elseif($rand[$i]==5){
$a5=$a5+1;
}elseif($rand[$i]==6){
$a6=$a6+1;
}
}
if($a1==3){ $won[0]="three_of_a_kind"; }
if($a1==4){ $won[1]="four_of_a_kind"; }
if($a1==5){ $won[2]="yahtzee"; }
if($a2==3){ $won[0]="three_of_a_kind"; }
if($a2==4){ $won[1]="four_of_a_kind"; }
if($a2==5){ $won[2]="yahtzee"; }
if($a3==3){ $won[0]="three_of_a_kind"; }
if($a3==4){ $won[1]="four_of_a_kind"; }
if($a3==5){ $won[2]="yahtzee"; }
if($a4==3){ $won[0]="three_of_a_kind"; }
if($a4==4){ $won[1]="four_of_a_kind"; }
if($a4==5){ $won[2]="yahtzee"; }
if($a5==3){ $won[0]="three_of_a_kind"; }
if($a5==4){ $won[1]="four_of_a_kind"; }
if($a5==5){ $won[2]="yahtzee"; }
if($a6==3){ $won[0]="three_of_a_kind"; }
if($a6==4){ $won[1]="four_of_a_kind"; }
if($a6==5){ $won[2]="yahtzee"; }
if(($a1==1) AND ($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1)){ $won[3]="large_strait"; }
if(($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1) AND ($a6==1)){ $won[3]="large_strait"; }
if(isset($won[0]) AND(($a1==2)OR($a2==2)OR($a3==2)OR($a4==2)OR($a5==2)OR($a6==2))){
$won[4]="full_house";
unset ($won[0]);
}
echo("</tr></table>");
for($i=0; $i<=5; $i++){
if(isset($won[$i])){
$gewonnen=$i;
}
}
if(isset($won[0])){ $winst=$_SESSION["inzet_yahtzee"]; }//je geld terug
elseif(isset($won[1])){ $winst=$_SESSION["inzet_yahtzee"]/100*180; }//80% winst
elseif(isset($won[2])){ $winst=$_SESSION["inzet_yahtzee"]/100*300; }//200% winst
elseif(isset($won[3])){ $winst=$_SESSION["inzet_yahtzee"]/100*150; }//50% winst
elseif(isset($won[4])){ $winst=$_SESSION["inzet_yahtzee"]/100*130; }//30% winst
if(!isset($gewonnen)){
echo "Helaas, je hebt niks gewonnen";
}else{
echo "Je hebt ".$won[$gewonnen];
echo "<br>Je winst is ".$winst;
}
echo("<br><a href=yahtzee.php>Nog een keertje</a>");
}
?>