Numero aleatorio

Wiki: Los usuarios registrados de DesarrolloWeb.com pueden modificar los contenidos y realizar aportaciones en esta sección.
  • Dar una respuesta
Da una respuesta
Votos útiles (0) inútiles (1)
Discusión creada por MCLANES el 22/08/2011

Categoría wiki: PHP

Tengo un problema con un programa que lo que hace es pedirle un numero al usuario, y el servidor va generando numeros aleatorios y en 10 intentos tiene que acertar el numero del usuario

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>

Adivina el nombre

</title>

</head>



<body>

<?php

/*Comprova que sigui la primera vegada ke entrem al programa, si ho es crea el Formulari sino el processa*/

if (filter_has_var(INPUT_POST, "numeroUsuari") && filter_has_var(INPUT_POST, "submit")) {



procesaFormulari();





}else{



creaFormulari();









}





function procesaFormulari(){



$numeroUsuari = filter_input(INPUT_POST, "numeroUsuari");

$intents = $_POST['intents'];

$control = filter_input(INPUT_POST, "control");

$numeroAleatori = rand(1,100);

control($numeroAleatori,$numeroUsuari,$intents);







if ($numeroUsuari == $numeroAleatori){

$resultat = "L'HAS CLAVAT";

numeroEncertat($resultat);







}elseif( $intents == 0){



$resultat = "L'HAS CAGAT TORNA'HI";

numeroErrat($resultat);



}elseif( $control== 2){



$numeroAleatori = rand($numeroAleatori,100);



control($numeroAleatori,$numeroUsuari,$intents);



}elseif ($control == 1){







$numeroAleatori = rand(1,$numeroAleatori);



control($numeroAleatori, $numeroUsuari, $intents);



}

}

?>







<?php

function creaFormulari() {



print <<<HERE

<h2>Introdueix un nombre aleatori</h2>

<form method = "post" action ="">





<input type = "hidden"

name = "numeroAleatori"

value = "$numeroAleatori"/>





<input type = "text"

name = "numeroUsuari"/>



<input type = "submit"

name = "submit"

value = "Numero"/>







</form>

HERE;

}



function control($numeroAleatori,$numeroUsuari,$intents = 10){

print <<< HERE

<h3>El Nombre de l'ordinador es $numeroAleatori</h3>

<h3>El Nombre que has introduit es $numeroUsuari</h3>





<form method = "post" action =""/>



<input type = "hidden"

name = "numeroUsuari"

value = "$numeroUsuari"/>

<input type = "hidden"

name = "intents"

value = " $intents "/>

<input type = "radio"

name = "control"

value = "1"/>Gran</br>

<input type = "radio"

name = "control"

value = "2"/>Petit

<button>

Envia

</button>

</form>

<h3>Li queden $intents intents al ordinador</h3>

HERE;





}



function numeroErrat($resultat){

echo $resultat;

?>

<form method = "post"

action = ""/>



<input type = "submit"

value = "TORNA'HI"/>

</form>



<?php } ?>

<?php

function numeroEncertat($resultat){

echo $resultat;

?>

<form method = "post"

action = ""/>



<input type = "submit"

value = "TORNA'HI"/>

</form>

<?php } ?>

</body>

</html>

para ir guiando al servidor, le tienes que decir si el numero que ha entrado es más pequeño o más grande que el que ha introducido el usuario

Últimas respuestas enviadas
22/08/2011 - Respuesta de eugim
Lo siento pero no tengo tiempo de mirar tu código... si tienes una duda concreta quizás alguien te pueda ayudar.
Votos útiles (0) inútiles (0)
Categoría relacionada
+ PHP
Donaciones
Si piensas que te hemos ayudado y merecemos tu apoyo económico...