Skip to content
Snippets Groups Projects
Commit aaa4fddd authored by Amel Abdic's avatar Amel Abdic :8ball:
Browse files

Added same color for background bubbles (win animation/draw animation), Added...

Added same color for background bubbles (win animation/draw animation), Added freeze for chips when some player wins, Added restart button functionality, reszied handcursor, added more bubbles to the background
parent a75c6458
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,15 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -5,13 +5,15 @@ document.addEventListener('DOMContentLoaded', () => {
const flaechen = document.querySelectorAll('.grid div'); const flaechen = document.querySelectorAll('.grid div');
const ergebnis = document.querySelector('#result'); const ergebnis = document.querySelector('#result');
const ergebnis2 = document.querySelector('#result2'); const ergebnis2 = document.querySelector('#result2');
const bubbles1 = document.querySelector('.bubbles span'); const bubbles1 = document.querySelectorAll('.bubbles span:nth-child(odd)');
const bubbles2 = document.querySelector('.bubbles span:nth-child(even)'); const bubbles2 = document.querySelectorAll('.bubbles span:nth-child(even)');
const takenChips = document.querySelectorAll('.grid div');
const displayCurrentPlayer = document.querySelector('#current-player'); const displayCurrentPlayer = document.querySelector('#current-player');
// Variable für den aktuellen Spieler (1 oder 2) // Variable für den aktuellen Spieler (1 oder 2)
let currentPlayer = 1; let currentPlayer = 1;
let gameActive = true;
//Hier werden alle potentielle gewinn Flächen abgespeichert //Hier werden alle potentielle gewinn Flächen abgespeichert
// 4 Flächen müssen mit der gleichen Farbe belegt sein // 4 Flächen müssen mit der gleichen Farbe belegt sein
...@@ -123,6 +125,7 @@ ws.onmessage = function(event) { ...@@ -123,6 +125,7 @@ ws.onmessage = function(event) {
}; };
// Funktion, um eine Spielmarke in der angegebenen Spalte zu platzieren // Funktion, um eine Spielmarke in der angegebenen Spalte zu platzieren
function placeChipInColumn(column) { function placeChipInColumn(column) {
if (!gameActive) return;
// Beginne am unteren Ende der Spalte und suche das erste freie Feld // Beginne am unteren Ende der Spalte und suche das erste freie Feld
for (let i = 5; i >= 0; i--) { for (let i = 5; i >= 0; i--) {
const index = i * 7 + column; const index = i * 7 + column;
...@@ -143,6 +146,14 @@ function placeChipInColumn(column) { ...@@ -143,6 +146,14 @@ function placeChipInColumn(column) {
break; break;
} }
} }
}
function checkForDraw(){
for (let i = 0; i < flaechen.length; i++) {
if (!flaechen[i].classList.contains('taken')) {
return false;
}
}
return true;
} }
// DIese Methode Überprüft jede Gewinnkombination // DIese Methode Überprüft jede Gewinnkombination
function checkBoard() { function checkBoard() {
...@@ -161,10 +172,12 @@ function placeChipInColumn(column) { ...@@ -161,10 +172,12 @@ function placeChipInColumn(column) {
{ {
ergebnis.innerHTML = 'Spieler 1 siegt!' ergebnis.innerHTML = 'Spieler 1 siegt!'
ergebnis2.innerHTML = 'Spieler 1 siegt!' ergebnis2.innerHTML = 'Spieler 1 siegt!'
bubbles1.style.background = '#ff0000' bubbles2.forEach(bubble => {
bubbles2.style.background = '#ff0000' bubble.style.background = '#ff0000';
bubbles1.style.boxShadow = '#ff000044' bubble.style.boxShadow = '0 0 10px #ff0000';
bubbles2.style.boxShadow = '#ff000044' });
gameActive = false;
return;
} }
if ( if (
...@@ -176,17 +189,31 @@ function placeChipInColumn(column) { ...@@ -176,17 +189,31 @@ function placeChipInColumn(column) {
{ {
ergebnis.innerHTML = 'Spieler 2 siegt!' ergebnis.innerHTML = 'Spieler 2 siegt!'
ergebnis2.innerHTML = 'Spieler 2 siegt!' ergebnis2.innerHTML = 'Spieler 2 siegt!'
bubbles1.style.background = '#ffff00' bubbles1.forEach(bubble => {
bubbles2.style.background = '#ffff00' bubble.style.background = '#ffff00';
bubbles1.style.boxShadow = '#ffff0044' bubble.style.boxShadow = '0 0 10px #ffff00';
bubbles2.style.boxShadow = '#ffff0044' });
gameActive = false;
return;
}
if(gewinnFlaechen.length - 1 === y && checkForDraw()){
ergebnis.innerHTML = 'Unentschieden!';
ergebnis2.innerHTML = 'Unentschieden!';
bubbles1.forEach(bubbleodd => {
bubbleodd.style.background = '#ffffff';
bubbleodd.style.boxShadow = '0 0 10px #ffffff';
});
bubbles2.forEach(bubbleeven => {
bubbleeven.style.background = '#ffffff';
bubbleeven.style.boxShadow = '0 0 10px #ffffff';
});
} }
} }
} }
// Fügt jedem Feld im Grid einen Klick-Event-Listener hinzu // Fügt jedem Feld im Grid einen Klick-Event-Listener hinzu
for (let i = 0; i < flaechen.length; i++) { for (let i = 0; i < flaechen.length; i++) {
flaechen[i].onclick = () => { flaechen[i].onclick = () => {
if (!gameActive) return;
// Überprüft, ob das darüberliegende Feld besetzt ist und das aktuelle Feld frei ist, um die Gültigkeit des Zuges zu sichern // Überprüft, ob das darüberliegende Feld besetzt ist und das aktuelle Feld frei ist, um die Gültigkeit des Zuges zu sichern
if (flaechen[i + 7].classList.contains('taken') &&!flaechen[i].classList.contains('taken')) { if (flaechen[i + 7].classList.contains('taken') &&!flaechen[i].classList.contains('taken')) {
if (currentPlayer == 1) { // Wenn Spieler Eins am Zug ist if (currentPlayer == 1) { // Wenn Spieler Eins am Zug ist
...@@ -212,5 +239,9 @@ function simulateClick(divElement) { ...@@ -212,5 +239,9 @@ function simulateClick(divElement) {
} }
} }
const startButton = document.getElementById('restartButton');
startButton.addEventListener('click', () => {
location.reload()
});
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
<script type="module" src="app.js" charset="utf-8" defer></script> <script type="module" src="app.js" charset="utf-8" defer></script>
</head> </head>
<body> <body>
<div class="backgroundContainer"> <div class="backgroundContainer">
<button id="restartButton"><p id="test">RESTART</p></button>
<div class="bubbles"> <div class="bubbles">
<span style="--i:11"></span> <span style="--i:11"></span>
<span style="--i:12"></span> <span style="--i:12"></span>
...@@ -42,6 +44,11 @@ ...@@ -42,6 +44,11 @@
<span style="--i:13"></span> <span style="--i:13"></span>
<span style="--i:28"></span> <span style="--i:28"></span>
<span style="--i:26"></span>
<span style="--i:17"></span>
<span style="--i:13"></span>
<span style="--i:28"></span>
...@@ -109,8 +116,8 @@ ...@@ -109,8 +116,8 @@
<div class="taken"></div> <div class="taken"></div>
</div> </div>
</div> </div>
<img id="cursor0" src="file.png" width="15" height="20" alt="Cursor 1" style="position: absolute;"/> <img id="cursor0" src="file.png" width="30" height="40" alt="Cursor 1" style="position: absolute;"/>
<img id="cursor1" src="file.png" width="15" height="20" alt="Cursor 2" style="position: absolute;"/> <img id="cursor1" src="file.png" width="30" height="40" alt="Cursor 2" style="position: absolute;"/>
</div> </div>
</div> </div>
......
...@@ -178,7 +178,15 @@ button:hover { ...@@ -178,7 +178,15 @@ button:hover {
font-family: "Comic Sans MS"; font-family: "Comic Sans MS";
color: green; color: green;
font-size: 50px; font-size: 50px;
} }
#restartButton{
position: absolute;
background:green;
}
#test{
color: black;
font-family: "Comic Sans MS";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment