<?php
startsession();
if(isset($_POST["1"])){
//stenen kiezen(eerste keer)
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"; }
{
echo "Three of a Kind!";
}
if($a1==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a1==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if($a2==3){ $won[0]="three_of_a_kind"; }
{
echo "Three of a Kind!";
}
if($a2==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a2==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if($a3==3){ $won[0]="three_of_a_kind"; }
{
echo "Three of a Kind!";
}
if($a3==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a3==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if($a4==3){ $won[0]="three_of_a_kind"; }
{
echo "Three of a Kind!";
}
if($a4==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a4==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if($a5==3){ $won[0]="three_of_a_kind"; }
{
echo "Three of a Kind!";
}
if($a5==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a5==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if($a6==3){ $won[0]="three_of_a_kind"; }
{
echo "Three of a Kind!";
}
if($a6==4){ $won[1]="four_of_a_kind"; }
{
echo "Four of a kind!";
}
if($a6==5){ $won[2]="yahtzee"; }
{
echo "Yahtzee!";
}
if(($a1==1) AND ($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1)){ $won[3]="large_strait"; }
{
echo "Grote straat!";
}
if(($a2==1) AND ($a3==1) AND ($a4==1) AND ($a5==1) AND ($a6==1)){ $won[3]="large_strait"; }
{
echo "Grote straat!";
}
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 "Full house!";
}
}
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>");
}
?>