user9134157
user9134157

Reputation:

turn-based game how switch between 2 players

I am coding my first POO project. Could you help to switch from one player to another? I know my code is far from perfect. I think I have all the elements but I have trouble using them. if someone with more experience could help me. All in JavaScript and for mooving I would like use jQuery.

Currently the code works well, in a main.js file I have a function that defines which begins. I move 3 times the player selected by random and after I should switch between the characters but I can not. Thank's.

Upvotes: 0

Views: 356

Answers (1)

trincot
trincot

Reputation: 350147

First a remark: using jQuery does not mean you just assign properties to variables that start with $. Sometimes programmers using jQuery name their variables like that, but only to denote jQuery objects (containing zero or more DOM object references), not just any value.

Now to why your code does not work:

Doing $compteur-- does not affect this.compteur. Those two variables contain primitive values and so changing one has no effect on the other: they live separate lives.

Replace the definition of $compteur = this.compteur with the definition of that :

var that = this;

And then replace $compteur-- with:

that.compteur--;

Upvotes: 1

Related Questions