* @copyright 2023 Bartolomé Sintes Marco
* @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
* @version 2023-12-05
* @link https://www.mclibre.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
// Se accede a la sesión
session_name("simon-4");
session_start();
$colores = ["red", "yellow", "green", "blue"];
// Reinicia cuando falta alguno o cuando fallo es true
if (!isset($_SESSION["longitud"]) || !isset($_SESSION["objetivo"]) || !isset($_SESSION["jugador"]) || !isset($_SESSION["fallo"]) || !isset($_SESSION["completado"]) || $_SESSION["fallo"]) {
$_SESSION["longitud"] = 3;
unset($_SESSION["objetivo"]);
for ($i = 0; $i < $_SESSION["longitud"]; $i++) {
$_SESSION["objetivo"][] = $colores[array_rand($colores)];
}
$_SESSION["jugador"] = [];
$_SESSION["fallo"] = false;
$_SESSION["completado"] = false;
}
if ($_SESSION["completado"]) {
$_SESSION["longitud"] += 1;
unset($_SESSION["objetivo"]);
for ($i = 0; $i < $_SESSION["longitud"]; $i++) {
$_SESSION["objetivo"][] = $colores[array_rand($colores)];
}
$_SESSION["jugador"] = [];
$_SESSION["fallo"] = false;
$_SESSION["completado"] = false;
}
?>
Simon (4).
Minijuegos. Sesiones.
Ejercicios. PHP. Bartolomé Sintes Marco. www.mclibre.org