|
|
|
@ -46,6 +46,10 @@ function drawPieces() {
|
|
|
|
|
field.innerText = "X";
|
|
|
|
|
} else if (field.piece === 2) {
|
|
|
|
|
field.innerText = "O";
|
|
|
|
|
} else if (field.piece === 11) {
|
|
|
|
|
field.innerText = "XX";
|
|
|
|
|
} else if (field.piece === 22) {
|
|
|
|
|
field.innerText = "OO";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -57,13 +61,13 @@ function selectField(field){
|
|
|
|
|
somethingIsSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!somethingIsSelected && ((field.piece === 1 && turnTotal%2 === 1)||(field.piece === 2 && turnTotal%2 === 0))) {
|
|
|
|
|
if(!somethingIsSelected && (((field.piece === 1 || field.piece === 11) && turnTotal%2 === 1)||((field.piece === 2 || field.piece === 22) && turnTotal%2 === 0))) {
|
|
|
|
|
field.style.backgroundColor = "rgb(16,43,202, 0.3)";
|
|
|
|
|
field.selected = 1;
|
|
|
|
|
if(field.piece === 1){
|
|
|
|
|
if(field.piece === 1 || field.piece === 11){
|
|
|
|
|
selectedPiece = field;
|
|
|
|
|
validMovesPlayer1(field);
|
|
|
|
|
} else if (field.piece === 2){
|
|
|
|
|
} else if (field.piece === 2 || field.piece === 22){
|
|
|
|
|
selectedPiece = field;
|
|
|
|
|
validMovesPlayer2(field);
|
|
|
|
|
}
|
|
|
|
@ -72,7 +76,7 @@ function selectField(field){
|
|
|
|
|
somethingIsSelected = false;
|
|
|
|
|
resetValidMoves();
|
|
|
|
|
} else if (field.validMove !== 0){
|
|
|
|
|
field.piece = selectedPiece.piece;
|
|
|
|
|
field.piece = movePiece(field, selectedPiece);
|
|
|
|
|
selectedPiece.piece = 0;
|
|
|
|
|
drawPieces();
|
|
|
|
|
resetValidMoves();
|
|
|
|
@ -132,7 +136,7 @@ function validMovesPlayer1(field){
|
|
|
|
|
left = document.getElementById("field" + (field.fieldNum - 1).toString());
|
|
|
|
|
if(left.piece === 0){
|
|
|
|
|
left.validMove = 1;
|
|
|
|
|
} else if (left.piece === 2){
|
|
|
|
|
} else if (left.piece === 2 || left.piece === 22){
|
|
|
|
|
left.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -140,19 +144,19 @@ function validMovesPlayer1(field){
|
|
|
|
|
right = document.getElementById("field" + (field.fieldNum + 1).toString());
|
|
|
|
|
if(right.piece === 0){
|
|
|
|
|
right.validMove = 1;
|
|
|
|
|
} else if (right.piece === 2){
|
|
|
|
|
} else if (right.piece === 2 || right.piece === 22){
|
|
|
|
|
right.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((field.fieldNum - 9) >= (rowMin - 8) && (field.fieldNum - 9) >= 0) {
|
|
|
|
|
topLeft = document.getElementById("field" + (field.fieldNum - 9).toString());
|
|
|
|
|
if (topLeft.piece === 2){
|
|
|
|
|
if (topLeft.piece === 2 || topLeft.piece === 22){
|
|
|
|
|
topLeft.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((field.fieldNum - 7) <= (rowMax - 8) && (field.fieldNum - 7) >= 0) {
|
|
|
|
|
topRight = document.getElementById("field" + (field.fieldNum - 7).toString());
|
|
|
|
|
if (topRight.piece === 2){
|
|
|
|
|
if (topRight.piece === 2 || topRight.piece === 22){
|
|
|
|
|
topRight.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -213,7 +217,7 @@ function validMovesPlayer2(field){
|
|
|
|
|
left = document.getElementById("field" + (field.fieldNum - 1).toString());
|
|
|
|
|
if(left.piece === 0){
|
|
|
|
|
left.validMove = 1;
|
|
|
|
|
} else if (left.piece === 1){
|
|
|
|
|
} else if (left.piece === 1 || left.piece === 11){
|
|
|
|
|
left.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -221,19 +225,19 @@ function validMovesPlayer2(field){
|
|
|
|
|
right = document.getElementById("field" + (field.fieldNum + 1).toString());
|
|
|
|
|
if(right.piece === 0){
|
|
|
|
|
right.validMove = 1;
|
|
|
|
|
} else if (right.piece === 1){
|
|
|
|
|
} else if (right.piece === 1 || right.piece === 11){
|
|
|
|
|
right.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((field.fieldNum + 7) >= (rowMin + 8) && (field.fieldNum + 7) < 64) {
|
|
|
|
|
bottomLeft = document.getElementById("field" + (field.fieldNum + 7).toString());
|
|
|
|
|
if (bottomLeft.piece === 1){
|
|
|
|
|
if (bottomLeft.piece === 1 || bottomLeft.piece === 11){
|
|
|
|
|
bottomLeft.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((field.fieldNum + 9) <= (rowMax + 8) && (field.fieldNum + 9) < 64) {
|
|
|
|
|
bottomRight = document.getElementById("field" + (field.fieldNum + 9).toString());
|
|
|
|
|
if (bottomRight.piece === 1){
|
|
|
|
|
if (bottomRight.piece === 1 || bottomRight.piece === 11){
|
|
|
|
|
bottomRight.validMove = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -263,3 +267,12 @@ function advanceTurn(){
|
|
|
|
|
document.getElementById("turnTotal").innerText = "Game-Turn: "+turnTotal;
|
|
|
|
|
document.getElementById("turnPlayer").innerText = turnPlayer;
|
|
|
|
|
}
|
|
|
|
|
function movePiece(field, selectedPiece){
|
|
|
|
|
if((selectedPiece.piece === 1 && field.fieldNum < 8 && field.fieldNum >= 0)|| selectedPiece.piece === 11){
|
|
|
|
|
return 11;
|
|
|
|
|
} else if((selectedPiece.piece === 2 && field.fieldNum < 64 && field.fieldNum >= 56)|| selectedPiece.piece === 22){
|
|
|
|
|
return 22;
|
|
|
|
|
} else {
|
|
|
|
|
return selectedPiece.piece;
|
|
|
|
|
}
|
|
|
|
|
}
|