You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

2 years ago
class Player{
constructor(i, id, name){
this.turn = false;
this.pairs = 0;
this.cards = [];
this.id = id;
this.index = i;
this.name = name;
this.createDom();
this.updateDom();
}
static getById(id){
for (let p of game.players){
if (p.id === id) return p;
}
}
addPairs(pairs){
this.pairs += pairs;
this.updateDom();
}
updateDom(){
this.dom.find(".pairs-label").html("Pairs: " + this.pairs);
}
createDom(){
if (this.index % 2 == 0) this.dom = $("#left > div:eq(" + this.index / 2 + ")");
else this.dom = $("#right > div:eq(" + (this.index - 1) / 2 + ")");
this.dom.find("span").html(this.name);
}
isIn(players){
for (let p of players){
if (p.id === this.id) return true;
}
return false;
}
hasTurn(turn){
if (turn == null) return this.turn;
this.turn = turn;
if (turn) this.dom.find(".has-turn").css("background-color", "green");
else this.dom.find(".has-turn").css("background-color", "rgba(0, 0, 0, 0)");
}
}