note 59728 deleted from ref.session by dmytton

From: Date: Wed, 14 Dec 2005 14:53:46 +0000
Subject: note 59728 deleted from ref.session by dmytton
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100137@lists.php.net to get a copy of this message
Note Submitter: Reason: useless ---- ok...i'll want to post a simply game that uses sessions...so you'll understand how important sessions are for php and html! Please name it "ahorcado.php". <?php // Start or revover session session_start(); include("funciones.php"); // There is a game in play if(isset($_POST["palabra"])) {//New game! $_SESSION["palabra"]=$_POST["palabra"]; $_SESSION["max_intentos"]=$_POST["max_intentos"]; $_SESSION["partida_en_curso"]=true; $_SESSION["intentos"]=0; $_SESSION["letras"]=""; juega(); } else { if($_SESSION["partida_en_curso"]==true) { $duplicado=false; for($i=0;$i<(strlen($_SESSION["letras"])) ;$i++) { if(( $_SESSION["letras"]{$i} )==($_POST["letra"]) ){ $duplicado=true;} } if ($duplicado==false) { $_SESSION["letras"]= $_SESSION["letras"] . $_POST["letra"]; } $_SESSION["intentos"]= $_SESSION["intentos"] + 1; $restantes= ($_SESSION["max_intentos"]) - ($_SESSION["intentos"]); if($_SESSION["intentos"] < ($_SESSION["max_intentos"] + 1 )){ juega(); } else { $_SESSION["partida_en_curso"]=false; echo abre_web("AHORCADO"); echo "<p>Lo sentimos, pero se te han acabado los intentos.</p>"; echo cierra_web(); } } else { echo abre_web("Bienvenidos al juego del ahorcado"); echo formulario_principal(); echo cierra_web(); } } function juega() { echo abre_web("AHORCADO"); echo "<p>Llevas ". $_SESSION["intentos"] ." intentos.</p>"; echo "<p>Has visto estas letras: ". $_SESSION["letras"] . "</p>"; $palabra=$_SESSION["palabra"]; $ganar="cierto"; for($i=0;$i<(strlen($palabra));$i++) { $esta="falso"; for($j=0;$j<(strlen($_SESSION["letras"]));$j++) { if($_SESSION["letras"]{$j}==$palabra{$i}) { echo $palabra{$i}; $esta="cierto"; } } if($esta=="falso") { $ganar="falso"; echo "-"; } } if($ganar=="cierto") { echo "<h1>HAS GANADO!!!!!</h1>"; $_SESSION["partida_en_curso"]=false; } else { $salida=<<<pre <form action ="ahorcado" method = "post"> <p>Introduce una letra.</p> <br> <input type ="text" name ="letra"/> <br> <input type = "submit" value= "JUGAR"/> pre; } echo $salida; echo cierra_web(); } ?>

« previous php.notes (#100137) next »