<?php


include('conf.php');
include('commun/commun.php');


if( ( !$scPartie->exist() || $scPartie->statut == 0 ) || !$scMoi->exist() ) {
  include('commun/menu.php');
  exit();
}



function affichePlateauCase($l, $c, $j) {
  echo '<td';
    if( (($l == 0 || $l == 6) && ($c > 0 && $c < 7)) || ($l > 0 && $l < 6) ) {
      echo ' id="PlateauCase_User'.$j->id;

      if($l == 0) {
        //if($c > 0 && $c < 7)
        echo '_Temple'.$c;
      }
      elseif($l == 6) {
        //if($c > 0 && $c < 7)
        echo '_Meeple'.($c + 5);
      }
      else {
        if($c == 0) echo '_Meeple'.$l;
        elseif($c == 7) echo '_Temple'.($l + 6);
        else echo '_Case'.(($l - 1) * 6 + $c);
      }

      echo '"';
    }
  echo '>';

  echo '<img src="src/plateau_';
    if($l == 0) {
      if($c == 0) echo 'haut-gauche';
      elseif($c == 1) echo 'haut-presquegauche';
      elseif($c == 7) echo 'haut-droite';
      else echo 'haut';
    }
    elseif($l == 6) {
      if($c == 0) echo 'bas-gauche';
      elseif($c == 7) echo 'bas-droite';
      else echo 'bas';
    }
    else {
      if($c == 0) echo 'gauche';
      elseif($c == 7) {
        if($l == 5) echo 'presquebas-droite';
        else echo 'droite';
      }
      else echo 'case';
    }
  echo '.png" />';

  echo '</td>';
}



function affichePlateauJoueur($j) {
  global $scMoi;

  echo '<table class="plateau">';

  if($j->id != $scMoi->id)
    echo '<tr><td colspan=8 class="plateau-nom">'.$j->nom.'</td><td id="Plateau_User'.$j->id.'_Joue"></td></tr>';

  for($l = 0 ; $l < 7 ; $l++) {
    echo '<tr>';
    for($c = 0 ; $c < 8 ; $c++)
      affichePlateauCase($l, $c, $j);

    if($l == 0) echo '<td><img src="src/diamant_gros.png" /><div class="nbr-diamant nbr-infos" id="Plateau_User'.$j->id.'_DiamantNbr">0</div></td>';
    elseif($l == 1) echo '<td><img src="src/or_gros.png" /><div class="nbr-or nbr-infos" id="Plateau_User'.$j->id.'_OrNbr">0</div></td>';
    elseif($l == 6) echo '<td><div class="calcul-total" id="Plateau_User'.$j->id.'_TotalNbr">0</div></td>';
    else echo '<td><img src="src/temple'.($l - 1).'.png" /><div class="nbr-temple'.($l - 1).' nbr-infos" id="Plateau_User'.$j->id.'_Temple'.($l - 1).'Nbr"></div></td>';

    echo '</tr>';
    echo "\n";
  }


  echo '</table>';
}




?>
<html>
<head>
  <title><?php echo $__CONF['nom']; ?></title>
  <link rel="stylesheet" type="text/css" href="css/jeu.css" />
  <script type= "text/javascript" src="commun/js/jquery-3.5.0.min.js"></script>
  <script type= "text/javascript" src="js/jeu.js"></script>
  <script type="text/javascript">
var scInput_JoueurId = <?php echo $scMoi->id; ?>;
var scInput_JeuNom = '<?php echo $__CONF['nom']; ?>';
  </script>
</head>
<body>


<div class="zone-autres">
  <?php foreach($scJoueurs as $j) { ?>
  <div class="zone-autres-plateau">
    <?php affichePlateauJoueur($j); ?>
  </div>
  <?php } ?>
</div>


<div class="zone-moi">
  <div class="zone-moi-infos">
    <table>
      <tr>
        <td id="zoneInfosTuile">
          <div id="zoneInfosTuile_tuile" class="zone-moi-infos-tuile-tuile"></div>
          <div id="zoneInfosTuile_jeter" class="zone-moi-infos-tuile-jeter">Jeter ?</div>
        </td>
      </tr>
      <tr>
        <td id="zoneInfosReste">Reste : -</td>
      </tr>
      <tr>
        <td>Tr&eacute;sors suivants :</td>
      </tr>
      <?php for($i = 1 ; $i <= 4 ; $i++) { ?>
      <tr>
        <td><img src="src/temple<?php echo $i; ?>.png" /><div class="zone-moi-infos-temple<?php echo $i; ?> nbr-infos" id="zoneInfosTemple<?php echo $i; ?>"></div></td>
      </tr>
      <?php } ?>
    </table>
  </div>

  <div class="zone-moi-plateau">
    <?php affichePlateauJoueur($scMoi); ?>
  </div>

<?php

function afficheTuilesRestantes($t, $p) {
  echo '<td class="zone-moi-tuilesrestantes-nbr" id="TuileRestante_'.$t.$p.'">';
  echo '</td>';

  echo '<td class="zone-moi-tuilesrestantes-tuile">';
  echo '<img src="src/tuile_'.$t.'" />';
  if($p) echo '<img src="src/tuile_'.$p.'" />';
  echo '</td>';
}

?>


  <div class="zone-moi-tuilesrestantes">
    <table>
      <tr>
<?php afficheTuilesRestantes('1', ''); ?>
<?php afficheTuilesRestantes('1', 'd'); ?>
<?php afficheTuilesRestantes('1', 'o'); ?>
      </tr>
      <tr>
<?php afficheTuilesRestantes('2', ''); ?>
<?php afficheTuilesRestantes('2', 'd'); ?>
<?php afficheTuilesRestantes('2', 'o'); ?>
      </tr>
      <tr>
<?php afficheTuilesRestantes('3', ''); ?>
<?php afficheTuilesRestantes('4', ''); ?>
<?php afficheTuilesRestantes('4', 'd'); ?>
      </tr>
      <tr>
<?php afficheTuilesRestantes('5', ''); ?>
<?php afficheTuilesRestantes('6', ''); ?>
<?php afficheTuilesRestantes('7', ''); ?>
      </tr>
      <tr>
<?php afficheTuilesRestantes('8', 'd'); ?>
<?php afficheTuilesRestantes('9', ''); ?>
<?php afficheTuilesRestantes('9', 'd'); ?>
      </tr>
      <tr>
<?php afficheTuilesRestantes('10', ''); ?>
<?php afficheTuilesRestantes('10', 'd'); ?>
        <td colspan=2 rowspan=2>Tuiles restantes dans la pioche (dont la tuile en cours)</td>
      </tr>
      <tr>
<?php afficheTuilesRestantes('11', ''); ?>
<?php afficheTuilesRestantes('11', 'd'); ?>
      </tr>
    </table>
  </div>





</div>










<div class="bas-btn" id="basBoutons">
  <div class="bas-btn-terminer jeu-btn" id="basBoutonTerminer">Terminer la partie</div>
</div>


<div class="finpartie" id="finPartie">
  <div class="finpartie-titre">Fin de partie</div>
  <div class="finpartie-infos" id="finPartieInfos"></div>
  <div class="finpartie-btn jeu-btn" id="finPartieBtn">Nouvelle partie !</div>
</div>


</body>
</html>