1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| <?php if( empty(session_id()) ){ session_start(); } // ouverture de SESSION (important)
header('Content-type:text/html; charset=UTF-8'); // encodage UTF-8
error_reporting(E_ALL); // en TEST !!
// -------------------------
// Gestion d'erreurs
$msg_err = '';
// -------------------------
// ETAPE (step)
if( !empty($_GET['step']) )
{
$step = $_GET['step'];
}
if( !empty($_POST['step']) )
{
$step = $_POST['step'];
}
if( empty($step) )
{
$step = 1;
}
// -------------------------
// array de toutes les cartes
$deck_cards = [
'1P','RP','DP','VP','10P','9P','8P','7P','6P','5P','4P','3P','2P',
'1C','RC','DC','VC','10C','9C','8C','7C','6C','5C','4C','3C','2C',
'1K','RK','DK','VK','10K','9K','8K','7K','6K','5K','4K','3K','2K',
'1T','RT','DT','VT','10T','9T','8T','7T','6T','5T','4T','3T','2T'
];
// -------------------------
$hand = []; // array
$flop = []; // array
// -------------------------
// TRAITEMENT ETAPE 2
if( isset($_POST['goto2']) && $step == 2 )
{
if( empty($_POST['hand']) || count($_POST['hand']) != 2 ) // 2 cartes
{
$msg_err = 'Vous devez choisir 2 cartes';
$step = 1; // retour étape 1
}
if( !empty($_POST['hand']) )
{
$hand = $_POST['hand']; // array
}
}
// -------------------------
// TRAITEMENT ETAPE 3
if( isset($_POST['goto3']) && $step == 3 )
{
if( !empty($_POST['hand']) )
{
$hand = $_POST['hand']; // array
}
if( empty($_POST['flop']) || count($_POST['flop']) != 3 ) // 3 cartes
{
$msg_err = 'Vous devez choisir 3 cartes';
$step = 2; // retour étape 2
}
if( !empty($_POST['flop']) )
{
$flop = $_POST['flop']; // array
}
}
// -------------------------
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Poker</title>
<style>
/* images des cartes */
label { position:relative; }
input[type=checkbox] { position:absolute; visibility:hidden; } /* on masque les checkbox */
img { display:inline-block; width:100px; height:146px; }
input[type=checkbox] + img { width:50px; height:73px; border:5px solid transparent; }
input[type=checkbox]:checked + img { border:5px solid green; }
input[type=checkbox]:disabled + img { border:5px solid lightgrey; opacity:0.5; }
/* error */
.msg-err { padding:10px; border:1px solid red; color:red; }
</style>
</head>
<body>
<?php if( !empty($msg_err) ){ ?>
<p class="msg-err"><?php echo $msg_err; ?></p>
<?php } ?>
<?php
// -------------------------
// ETAPE 1
if( $step == 1 )
{
?>
<h4>Choix des cartes de votre main (2 cartes) :</h4>
<form method="post" action="">
<input type="hidden" name="step" value="2" />
<?php // on affiche toutes les cartes
foreach( $deck_cards as $idx => $deck_card )
{
if($idx%13==0){ echo '<br/>'; }
$checked = ( !empty($hand) && in_array($deck_card, $hand) )? ' checked="checked"' : ''; // on précoche les choix (si existants)
?>
<label><input type="checkbox" name="hand[]" value="<?=$deck_card;?>"<?=$checked;?>><img src="imagesCartes/<?=$deck_card;?>.png" alt="<?=$deck_card;?>" /></label>
<?php
}
?>
<p><input type="submit" name="goto2" value="Valider"></p>
</form>
<?php
}
// -------------------------
// ETAPE 2
elseif( $step == 2 )
{
?>
<h4>Votre main :</h4>
<?php // on affiche la main (hand)
foreach( $hand as $idx => $card )
{
?>
<img src="imagesCartes/<?=$card;?>.png" alt="<?=$card;?>" />
<?php
}
?>
<h4>Choix des cartes pour le flop (3 cartes) :</h4>
<form method="post" action="">
<input type="hidden" name="step" value="3" />
<?php // on transmet la main (hand)
foreach( $hand as $idx => $card )
{
?>
<input type="hidden" name="hand[]" value="<?=$card;?>" />
<?php
}
?>
<?php // on affiche toutes les cartes
foreach( $deck_cards as $idx => $deck_card )
{
if($idx%13==0){ echo '<br/>'; } // passage à la ligne toutes les 13 cartes
$disabled = ( !empty($hand) && in_array($deck_card, $hand) )? ' disabled="disabled"' : ''; // on désactive les cartes déjà tirées
$checked = ( !empty($flop) && in_array($deck_card, $flop) )? ' checked="checked"' : ''; // on précoche les choix (si existants)
?>
<label><input type="checkbox" name="flop[]" value="<?=$deck_card;?>"<?=$checked;?><?=$disabled;?>><img src="imagesCartes/<?=$deck_card;?>.png" alt="<?=$deck_card;?>" /></label>
<?php
}
?>
<p><input type="submit" name="goto3" value="Valider"></p>
</form>
<?php
}
// -------------------------
// ETAPE 3
elseif( $step == 3 )
{
?>
<h4>Votre main :</h4>
<?php // on affiche la main (hand)
foreach( $hand as $idx => $card )
{
?>
<img src="imagesCartes/<?=$card;?>.png" alt="<?=$card;?>" />
<?php
}
?>
<h4>Le flop :</h4>
<?php // on affiche le flop
foreach( $flop as $idx => $card )
{
?>
<img src="imagesCartes/<?=$card;?>.png" />
<?php
}
?>
<?php // ICI, il te reste à AFFICHER LES STATISTIQUES
// .......
?>
<p>Faire un autre test : <a href="?step=1">Tester à nouveau</a></p>
<?php
}
// -------------------------
?>
</body>
</html> |
Partager