Solved error of not removing cups after the 7th cup. Winner function was reworked, draw funktion was removed.

This commit is contained in:
2021-06-21 11:34:43 +02:00
parent 3a30e2a597
commit c2be377a92
5 changed files with 71 additions and 88 deletions
+22 -33
View File
@@ -62,12 +62,9 @@ Board.prototype.enableTurn = function() {
});
};
Board.prototype.highlightcups = function(pos) {
Board.prototype.highlightcups = function() {
var cups = this.cups;
alert('highlightcups');
pos.forEach(function(i) {
// cups[i].classList.add('colorRed');
});
cups.forEach(function(cup) {
cup.setAttribute('marked', 'true');
@@ -208,18 +205,12 @@ Board.prototype.doMark = function(cupId, label) {
*
* @param pos
*/
Board.prototype.doWinner = function(pos) {
Board.prototype.doWinner = function() {
this.disableAll();
this.highlightcups(pos);
this.highlightcups();
};
/**
*
*/
Board.prototype.doDraw = function() {
alert('doDraw');
this.lowlightcups();
};
/**
*
@@ -241,17 +232,23 @@ Board.prototype.highlightScoreboard = function(playerId) {
* @returns {{win: boolean, pos: Array}}
*/
Board.prototype.checkWinner = function() {
var counter=0;
var win = false;
this.cups.forEach(function(cup) {
if (cup.getAttribute('marked') === 'true') {
counter++;
}
});
if(counter === 10) {
win = true;
}
/*
var winPosition = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[6, 4, 2]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
];
var player = this.players[this.currentTurn];
@@ -268,7 +265,7 @@ Board.prototype.checkWinner = function() {
}
return false;
}, this);
}, this);*/
return {
win: win,
@@ -277,15 +274,7 @@ Board.prototype.checkWinner = function() {
};
/**
*
* @returns {boolean}
*/
Board.prototype.checkDraw = function() {
return this.cups.every(function(cup) {
return cup.textContent === this.players[0].label || cup.textContent === this.players[1].label;
}, this);
};
/**
*
+2 -4
View File
@@ -1,4 +1,4 @@
var socket = new WebSocket('ws://localhost:2667');
var socket = new WebSocket('ws://192.168.188.72:2667');
var events = {
outgoing: {
JOIN_GAME: 'csJoinGame',
@@ -114,9 +114,7 @@ socket.onmessage = function(event){
case events.incoming.GAME_OVER:
if (msg.data.player) {
board.doWinner(msg.data.pos);
} else {
board.doDraw();
board.doWinner();
}
socket.send(makeMessage(events.outgoing.QUIT, hero.id));