From 8941a5c5359853ad7d5030b4987d91c0d62abc9e Mon Sep 17 00:00:00 2001 From: ElGurkus Date: Thu, 5 Nov 2020 13:07:48 +0100 Subject: [PATCH] changed code -> added scoring changed index -> added scoring boxes changed style -> minor tweaks --- code.js | 34 ++++++++++++++++++++++++++++++++++ index.html | 3 +++ style.css | 6 +++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/code.js b/code.js index bbf4b7a..828529d 100644 --- a/code.js +++ b/code.js @@ -19,10 +19,17 @@ let turnTotal = 0; let turnPlayer; let piecesX; let piecesO; +let scoreX = 0; +let scoreCounterX = 100; +let scoreO = 0; +let scoreCounterO = 100; let gameOver = false; let winner; let somethingIsSelected = false; +document.getElementById("scoreCounter").innerText = "Score counter: 100"; +document.getElementById("scoreX").innerText = "Score X: 0"; +document.getElementById("scoreO").innerText = "Score O: 0"; for(let i = 0; i < 64; i++){ fieldId = i.toString(); document.getElementById("field"+fieldId).selected = 0; //Sorgt dafür dass alle Felder die selected variable haben und diese 0 ist @@ -82,6 +89,7 @@ function selectField(field){ somethingIsSelected = false; resetValidMoves(); } else if (field.validMove !== 0){ + score(field); field.piece = movePiece(field, selectedPiece); selectedPiece.piece = 0; drawPieces(); @@ -422,4 +430,30 @@ function checkWinCondition(){ } } } +} +function score (field){ + if(field.piece === 0 && turnPlayer === "Player-Turn: X" && scoreCounterX > 10){ + scoreCounterX -= 10; + } else if(field.piece === 0 && turnPlayer === "Player-Turn: O" && scoreCounterO > 10){ + scoreCounterO -= 10; + } else if (field.piece === 1){ + scoreO += scoreCounterO; + scoreCounterO = 100; + } else if (field.piece === 11){ + scoreO += ((scoreCounterO + 50) * 2) + scoreCounterO = 100; + } else if (field.piece === 2){ + scoreX += scoreCounterX; + scoreCounterX = 100; + } else if (field.piece === 2){ + scoreX += ((scoreCounterX + 50) * 2) + scoreCounterX = 100; + } + if(turnPlayer === "Player-Turn: X"){ + document.getElementById("scoreCounter").innerText = "Score counter: " + scoreCounterO; + } else if (turnPlayer === "Player-Turn: O"){ + document.getElementById("scoreCounter").innerText = "Score counter: " + scoreCounterX; + } + document.getElementById("scoreO").innerText = "Score O: " + scoreO; + document.getElementById("scoreX").innerText = "Score X: " + scoreX; } \ No newline at end of file diff --git a/index.html b/index.html index 56bbe3e..5f6ca85 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,9 @@
  • HighScore
  • yeet
  • yeet
  • +
  • yeet
  • +
  • yeet
  • +
  • yeet
  • Reset
  • Nickname
  • diff --git a/style.css b/style.css index 02ce949..46e4312 100644 --- a/style.css +++ b/style.css @@ -5,7 +5,7 @@ ul { overflow: hidden; background-color: #333; height: auto; - width: 800px; + width: 1000px; position: absolute; top: 5%; } @@ -19,11 +19,11 @@ li:last-child { border-right: none; } -li a, #turnTotal, #turnPlayer { +li a, #turnTotal, #turnPlayer, #scoreCounter, #scoreO, #scoreX { display: block; color: white; text-align: center; - padding: 14px 16px; + padding: 12px 14px; text-decoration: none; }