mardi 27 décembre 2016

How to loop an if statement [on hold]

I have an if statement which is used to control player turns. The functions within the if statement are click based, so the idea is that player 1 will click, then player 2, back to player 1 etc.

This is the code that I have so far

var player1turn=true;

if (player1turn) {
  recruitbuilderclickp1(cardsnames, allocatedcard, p1);
  mastclickp1(cardsnames, allocatedcard, p1);  
  player1turn = !player1turn;
  console.log(player1turn);
} else {
  recruitbuilderclickp2(cardsnames, allocatedcard, p2);
  mastclickp2(cardsnames, allocatedcard, p2);
  player1turn = !player1turn;
}

The problem which I am having is that once player 1 has had his turn, it is player 2's turn however this code isn't re-read and so nothing happens from that point on. How do I make it into a loop?

Aucun commentaire:

Enregistrer un commentaire