Skip to main content

how can i prevent from clicking twice in the same tile?

Im making a game and im trying to figure out how to prevent my X to be deleted when clicking twice in the same tile right now i can move my "X" around but it get's deleted if i click twice. ive tried boolean but im terrible with them . is there a way to do it with boolean or anything else ? Im a beginner at school.

var clique1fois = false;
var clique = null;
var aClique = false;

function deplacerPion(x) {
  if (aClique == true) {
    x.innerHTML = clique.innerHTML;
    clique.innerHTML = "";
    aClique = false;
    clique.style.border = "1px solid black";
    clique.style.height = "80px";
    clique.style.width = "80px";
  } else {
    x.style.border = "3px solid red";
    x.style.width = "76px";
    x.style.height = "76px";
    clique = x;
    aClique = true;
  }
}
td {
  height: 80px;
  width: 80px;
  text-align: center;
  font-size: 300%;
}

table {
  margin-left: auto;
  margin-right: auto;
}

#titre {
  text-align: center;
  font-size: 300%;
}
<div id="titre">Jeu de table</div>
<table border=1>
  <tr>
    <td onclick="deplacerPion(this)">X</td>
    <td onclick="deplacerPion(this)"></td>
  </tr>
</table>
Via Active questions tagged javascript - Stack Overflow https://ift.tt/JZcIChS

Comments