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
| <?php
session_start();
if (!isset($_SESSION['id'])) {
header ('Location: index.php');
exit();}
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$pdo = new PDO('mysql:host=127.0.0.1;dbname=espace_membre', 'root', '', $pdo_options);
if (isset($_SESSION['id']) AND isset($_SESSION['pseudo']))
{
echo 'Bonjour ' . $_SESSION['pseudo'];
}
// Position du joueur
$requete = $pdo->query('SELECT pos_x, pos_y, img_unite FROM unite, membres WHERE unite.id = membres.id');
while ($donnees = $requete->fetch())
{
$pos_x = $donnees['pos_x'];
$pos_y = $donnees['pos_y'];
$imgunite = $donnees['img_unite'];
}
// Définition de la map
$taille = 4;
$x_debut=$pos_x-$taille;
$x_fin=$pos_x+$taille;
$y_debut=$pos_y-$taille;
$y_fin=$pos_y+$taille;
//affichage de la carte
echo '<table border="1" cellspacing="0" cellpadding="0">'."\n";
echo '<tbody>'."\n";
echo '<tr><td height="40" width="40"> x<br> y</td>'."\n";
//on affiche les positions x sur la premiere ligne
for($x=$x_debut;$x<=$x_fin;$x++) echo '<td align="center" valign="middle" height="40" width="40">'.$x.'</td>'."\n";
//on affiche lignes par lignes la position y, les autres joueurs et les batiments
for ($y=$y_debut;$y<=$y_fin;$y++) {
echo'<tr witdh="40" height="40"><td align="center" valign="middle" height="40" width="40">'.$y.'</td>'."\n";//affichage de la position
for($x=$x_debut;$x<=$x_fin;$x++) {
if($x==$pos_x && $y==$pos_y) //si on est sur la position du joueur
echo "<td class='$imgunite' alt='.'></td>"; //on affiche l'avatar de votre perso
else
echo "<td class='t1'></td>"; //Sinon on affiche de l'herbe
}
echo '</tr>';
}
echo '</tbody></table>';
}
?> |