Created
May 1, 2017 23:58
-
-
Save everaldo/d25645b96e7ae117ece8deb12ea23236 to your computer and use it in GitHub Desktop.
Adivinhe um Número, utilizando Hidden Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Nome: Adivinhe um Número | |
Autor: Turma P2-1 | |
Data: 19/08/2015 | |
*/ | |
function imprime_vitoria(){ | |
$class_vitoria = "warning"; | |
echo <<<EOT | |
<div class="alert alert-$class_vitoria" role="alert"> | |
Ah Muleque! | |
</div> | |
EOT; | |
} | |
function imprime_maior(){ | |
$class_maior = "info"; | |
echo <<<EOT | |
<div class="alert alert-$class_maior" role="alert"> | |
Digite um número maior | |
</div> | |
EOT; | |
} | |
function imprime_menor(){ | |
$class_menor = "danger"; | |
echo <<<EOT | |
<div class="alert alert-$class_menor" role="alert"> | |
Digite um número menor | |
</div> | |
EOT; | |
} | |
function verifica_jogo($secret, $valor){ | |
//POG: Retorne quando GET | |
if($valor == null){ | |
return; | |
} | |
if($secret == $valor){ | |
imprime_vitoria(); | |
} | |
else if($secret > $valor){ | |
imprime_maior(); | |
} | |
else if($secret < $valor){ | |
imprime_menor(); | |
} | |
} | |
if (! empty($_POST["secret"])){ | |
$secret = $_POST["secret"]; | |
$valor = $_POST["valor"]; | |
} | |
else{ | |
$secret = rand(1,100); | |
$valor = null; | |
} | |
?> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Adivinhe o número </title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
<!-- Optional theme --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<?php verifica_jogo($secret, $valor); ?> | |
<form action='' method="POST"> | |
<input name="secret" type="hidden" | |
value="<?php echo $secret; ?>"> | |
<input name="valor" type="text" id="valor" | |
placeholder="digite um inteiro"> | |
<input type="submit" name="botao" value="Enviar"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment