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
|
////////// Niveau Facile//////////
// Test le niveau, si = à facile : Initialise un tableau en php en 4x4
if ($_SESSION["niveau"] == "facile")
{
$j = 1; //Ligne
while($j <= 4)
{
?>
<tr>
<?php
$i = 1; //Colonne
while($i <= 4)
{
$rand = rand(1, 16); // génére un nombre aléatoire
$inctab = 1; // Variable qui incrémente la dimenssions
while($inctab <=4)
{
if (in_array($rand, $_SESSION["tblidc"][$inctab])) // Test si la var $rand existe déjà dans la dimensions[$inctab]
{
$rand = rand(1, 16); // génére un nouveau nombre aléatoire
$inctab = 1; // remettre le tab a 1 pour refaire une vérif.
}
else
{
$inctab++;
}
}
// Test si la valeur de rand est plus grand que 8
?><td width="50" height="50" id ="cell_<?php $i.$j; ?>" ><?php
if ($rand <= 8)
{
?><img width="50" height="50" src="images/<?php echo $rand ?>.png" id ="img_<?php $i.$j; ?>" border="0" onClick="Click();"/><?php
}
else //Si le rand est plus grand que 8, on enlève 8 a celui-ci ce qui nous donne 9-8 = 1, 10-8 = 2, 11-8=3, etc...
{
?><img width="50" height="50" src="images/<?php echo $rand-8 ?>.png" id ="img_<?php $i.$j; ?>" border="0" onClick="Click();"/><?php
}?></td>
<?php
$_SESSION["tblidc"][$j][$i] = $rand; // Permet de mettre un chiffre aléa. pour chaque case, exemple en 1.1, 1.2, etc. à l'aide des var $j et $i.
$i++;
}
?>
</tr>
<?php
$j++;
}
} |
Partager