This repository has been archived on 2024-04-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
DeezCycle/vues/creerPartie_vue.php
2024-04-15 12:35:33 +02:00

72 lines
1.6 KiB
PHP

<?php
function champs_cartes($nom, $titre) {
$nbCartes = 1;
if (isset($_POST[$nom])) {
$nbCartes = (int) $_POST[$nom];
}
echo '<select id="' . $nom . '" name="' . $nom . '">';
for ($i = 1; $i <= 5; $i++) {
echo '<option value="' . $i . '"';
if ($i == $nbCartes) {
echo ' selected';
}
echo '>' . $i . '</option>';
}
echo '</select>';
echo '<label for="' . $nom . '">' . $titre . '</label><br/>';
if (isset($_POST[$nom])) {
return (int) $_POST[$nom];
}
return (int) 0;
}
function afficher_formulaire() {
$total = 0;
echo '<form class="formulaire_partie" method="post" action="#">';
$total += champs_cartes('nbCartesVertes', 'Nombre de cartes vertes');
$total += champs_cartes('nbCartesOranges', 'Nombre de cartes oranges');
$total += champs_cartes('nbCartesNoires', 'Nombre de cartes noires');
if($total > 0) {
echo '<div>Total : ' . $total . '</div>';
if ($total > 10) {
echo '<div> Trop de cartes !!!!!!</div>';
} else {
echo '<input type="submit" name="creerPartie" value="Créer une partie" />';
}
}
echo '<input type="submit" name="validerCartes" value="Valider le nombre de cartes" />';
echo '</form>';
}
?>
<div class="panneau_details">
<h2>Créer une partie</h2>
<?php
if (isset($_POST['creerPartie'])) {
$total = (int)$_POST['nbCartesVertes'] + (int)$_POST['nbCartesOranges'] + (int)$_POST['nbCartesNoires'];
if ($total < 10) {
creerPartie($_POST['nbCartesVertes'], $_POST['nbCartesOranges'], $_POST['nbCartesNoires']);
} else {
afficher_formulaire();
}
} else {
afficher_formulaire();
}
?>
</div>