diff --git a/code.js b/code.js index 4b0a15f..ad7d412 100644 --- a/code.js +++ b/code.js @@ -13,6 +13,8 @@ let bottomLeft; let rowMin; let rowMax; let selectedPiece; +let turnTotal = 0; +let turnPlayer; let somethingIsSelected = false; for(let i = 0; i < 64; i++){ @@ -32,6 +34,7 @@ for(let i = 0; i < 8; i++){ drawPieces(); resetValidMoves(); +advanceTurn(); function drawPieces() { for (let i = 0; i < 64; i++) { @@ -54,7 +57,7 @@ function selectField(field){ somethingIsSelected = true; } } - if(!somethingIsSelected && field.piece !== 0) { + if(!somethingIsSelected && ((field.piece === 1 && turnTotal%2 === 1)||(field.piece === 2 && turnTotal%2 === 0))) { field.style.backgroundColor = "rgb(16,43,202, 0.3)"; field.selected = 1; if(field.piece === 1){ @@ -78,6 +81,7 @@ function selectField(field){ document.getElementById("field"+fieldId).selected = 0; somethingIsSelected = false; } + advanceTurn(); } } function validMovesPlayer1(field){ @@ -248,4 +252,14 @@ function resetValidMoves(){ document.getElementById("field"+fieldId).validMove = 0; document.getElementById("field" + fieldId).style.backgroundColor = "rgb(255,255,255, 1)"; } +} +function advanceTurn(){ + turnTotal++; + if(turnTotal%2 === 0){ + turnPlayer = "Player-Turn: O"; + } else { + turnPlayer = "Player-Turn: X"; + } + document.getElementById("turnTotal").innerText = "Game-Turn: "+turnTotal; + document.getElementById("turnPlayer").innerText = turnPlayer; } \ No newline at end of file diff --git a/index.html b/index.html index 0a61a7c..ce061b5 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,8 @@ diff --git a/style.css b/style.css index db1deac..02ce949 100644 --- a/style.css +++ b/style.css @@ -19,7 +19,7 @@ li:last-child { border-right: none; } -li a { +li a, #turnTotal, #turnPlayer { display: block; color: white; text-align: center;