|
|
|
@ -15,6 +15,10 @@ let rowMax;
|
|
|
|
|
let selectedPiece;
|
|
|
|
|
let turnTotal = 0;
|
|
|
|
|
let turnPlayer;
|
|
|
|
|
let piecesX;
|
|
|
|
|
let piecesO;
|
|
|
|
|
let gameOver = false;
|
|
|
|
|
let winner;
|
|
|
|
|
let somethingIsSelected = false;
|
|
|
|
|
|
|
|
|
|
for(let i = 0; i < 64; i++){
|
|
|
|
@ -86,6 +90,7 @@ function selectField(field){
|
|
|
|
|
somethingIsSelected = false;
|
|
|
|
|
}
|
|
|
|
|
advanceTurn();
|
|
|
|
|
checkWinCondition();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function validMovesPlayer1(field){
|
|
|
|
@ -275,4 +280,31 @@ function movePiece(field, selectedPiece){
|
|
|
|
|
} else {
|
|
|
|
|
return selectedPiece.piece;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function checkWinCondition(){
|
|
|
|
|
piecesX = 0;
|
|
|
|
|
piecesO = 0;
|
|
|
|
|
for(let i = 0; i < 64; i++){
|
|
|
|
|
fieldId = i.toString();
|
|
|
|
|
if(document.getElementById("field"+fieldId).piece === 1){
|
|
|
|
|
piecesX++;
|
|
|
|
|
} else if(document.getElementById("field"+fieldId).piece === 11){
|
|
|
|
|
piecesX += 2;
|
|
|
|
|
} else if(document.getElementById("field"+fieldId).piece === 2){
|
|
|
|
|
piecesO++;
|
|
|
|
|
} else if(document.getElementById("field"+fieldId).piece === 22){
|
|
|
|
|
piecesO += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(piecesX >= (2 * piecesO)){
|
|
|
|
|
gameOver = true;
|
|
|
|
|
winner = 1;
|
|
|
|
|
document.getElementById("turnTotal").innerText = "Game Over!";
|
|
|
|
|
document.getElementById("turnPlayer").innerText = "X Won!";
|
|
|
|
|
} else if (piecesO >= (2 * piecesX)){
|
|
|
|
|
gameOver = true;
|
|
|
|
|
winner = 2;
|
|
|
|
|
document.getElementById("turnTotal").innerText = "Game Over!";
|
|
|
|
|
document.getElementById("turnPlayer").innerText = "O Won!";
|
|
|
|
|
}
|
|
|
|
|
}
|