T
T
townee2018-03-25 12:01:31
JavaScript
townee, 2018-03-25 12:01:31

Checking if a player can move with ES6 Class?

What is the way to determine whose move, I want that if turn: false the player can't move, if turn: true the player can move.
If State.gameStep = 1 then player 1 changes from false to true and he can move, then gameStep = 2, and player 1 turns again to false, and player 2 turns to true and he can move and so on in turn. How can this be implemented?
This is my class:

class State{
    constructor(){

        this.info = {
            name: this.playerName,
            win: 0,
            lose: 0,
            surrender: 0,
            playerId: 0,
            turn: false
        };

    }
}
State.playerId = 0;
State.gameStep = 0;

This is my Player class:
class Player extends State{
        constructor(name){
            super();
            State.playerId += 1;
            this.info.playerId = State.playerId;
            this.info.name = name;
        }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question