Hallo,
Ik ben nieuw op dit forum. Ik ben student en volg applicatie-ontwikkeling, eerstejaars in Den Bosch.
Ik wil Yahtzee in PHP maken als extra opdracht, maar ik weet niet hoe ik moet beginnen. (uitleg Yahtzee: http://hobby-en-overige.infonu.nl/spellen/29513-yahtzee-een-spannend-dobbelspel.html )
Heb al een Yahtzee script gevonden op internet, maar het is maar een beginnetje.
Het werkte met SQL en geld inzetten. Heb ik eruit proberen te halen maar ik kom veel errors tegen.
Kunnen jullie mij verder helpen?
Bij voorbaat dank :)
Toevoeging op 03/04/2011 17:48:31:
Dit is wat ik tot nu toe heb. Er zitten veel errors in.
<?php
start_session();
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>");
}
?>
12.782 views