Skip to content

Commit

Permalink
game front end 1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmavrotheris committed Dec 19, 2024
1 parent 3afbed4 commit c9d2d15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ <h3 class="text-center">Player 4</h3>

<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="script.js"></script>
<script src="js/game.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions public/js/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
document.addEventListener("DOMContentLoaded", () => {
const gameBoard = document.querySelector(".game-board");

// Δημιουργία του grid
for (let i = 0; i < 400; i++) { // 20x20 grid
const cell = document.createElement("div");
cell.addEventListener("click", () => {
cell.classList.toggle("active"); // Εναλλαγή κατάστασης κελιού
});
gameBoard.appendChild(cell);
}

// Δημιουργία κομματιών για κάθε παίκτη
const players = document.querySelectorAll(".player .pieces");
players.forEach((pieceContainer, index) => {
for (let i = 0; i < 10; i++) { // 10 κομμάτια ανά παίκτη
const piece = document.createElement("div");
piece.style.backgroundColor = getColor(index); // Χρώμα ανάλογα με τον παίκτη
pieceContainer.appendChild(piece);
}
});

// Reset λειτουργικότητα
document.getElementById("reset-game").addEventListener("click", () => {
document.querySelectorAll(".game-board div").forEach(cell => {
cell.classList.remove("active");
});
});
});

// Επιστρέφει διαφορετικό χρώμα για κάθε παίκτη
function getColor(playerIndex) {
const colors = ["#ff4d4d", "#4d79ff", "#4dff4d", "#ffff4d"]; // Κόκκινο, Μπλε, Πράσινο, Κίτρινο
return colors[playerIndex] || "#ccc";
}

0 comments on commit c9d2d15

Please sign in to comment.