2ちゃんねる ■掲示板に戻る■ 全部 1- 最新50    

■ このスレッドは過去ログ倉庫に格納されています

twigでexit the whileを作ってる

1 :勘違いしてる:2024/07/10(水) 20:52:59.48 ID:RcrXi80IV
{% set max_attempts = 3 %}<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
<title>Escape Game</title></head><body><h1>Escape Game</h1><p>Guess the secret number between 1 and 10!</p>
{# {{secret_number}} #}{% block content %}{% set attempts = attempts + 1 %}{% if attempts > max_attempts %}
<p>Sorry, you failed to guess the number within {{ max_attempts }} attempts.</p>
<p>The secret number was {{ secret_number }}.</p>{% endif %}
<form action="?attempts={{attempts}}&secret_number={{secret_number}}" method="post">
<label for="guess">Enter your guess (1-10):</label>
<input type="number" id="guess" name="guess" min="1" max="10" required>
<button type="submit">Guess</button></form>{% if guess == secret_number %}
<p>Congratulations! You guessed the secret number {{ secret_number }}!</p>{% else %}
<p>Sorry, that's not the correct number. Try again!</p>{% endif %}
{% endblock %}</body></html>

<?php
require_once 'vendor/autoload.php';
$loader = new \Twig\Loader\FilesystemLoader(__DIR__);
$twig = new \Twig\Environment($loader);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {$guess = $_POST['guess'];}else{$guess = 0;}
if (isset($_GET['attempts'])) {$attempts = $_GET['attempts'];}else{$attempts = 0;}
if (isset($_GET['secret_number'])) {$secret_number = $_GET['secret_number'];
}else{$secret_number = rand(1,10);}
echo $twig->render('escape_while.twig', ['guess' => $guess,'attempts' => $attempts,'secret_number' => $secret_number]);
?>

総レス数 1
2 KB
掲示板に戻る 全部 前100 次100 最新50
read.cgi ver.24052200