Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tic_Tac_Toe_Neon added this game #4667

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Games/Tic_Tac_Toe_Neon/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic-Tac-Toe</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="game-container">
<h1>Tic-Tac-Toe Neon</h1>
<div id="game-board">
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
</div>
<button id="restartButton">Restart Game</button>
</div>
<script src="script.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions Games/Tic_Tac_Toe_Neon/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tic tac toe game with neon color which makes an ambient immence for gameplay
86 changes: 86 additions & 0 deletions Games/Tic_Tac_Toe_Neon/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const cells = document.querySelectorAll('[data-cell]');
const board = document.getElementById('game-board');
const restartButton = document.getElementById('restartButton');
let isCircleTurn;

const WINNING_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
];

const startGame = () => {
isCircleTurn = false;
cells.forEach(cell => {
cell.classList.remove('x');
cell.classList.remove('circle');
cell.innerHTML = ''; // Clear the cell's content
cell.removeEventListener('click', handleClick);
cell.addEventListener('click', handleClick, { once: true });
});
setBoardHoverClass();
};

const handleClick = (e) => {
const cell = e.target;
const currentClass = isCircleTurn ? 'circle' : 'x';
placeMark(cell, currentClass);
if (checkWin(currentClass)) {
endGame(false);
} else if (isDraw()) {
endGame(true);
} else {
swapTurns();
setBoardHoverClass();
}
};

const endGame = (draw) => {
if (draw) {
alert("Draw!");
} else {
alert(`${isCircleTurn ? "O's" : "X's"} Wins!`);
}
};

const isDraw = () => {
return [...cells].every(cell => {
return cell.classList.contains('x') || cell.classList.contains('circle');
});
};

const placeMark = (cell, currentClass) => {
cell.classList.add(currentClass);
cell.innerHTML = currentClass === 'x' ? 'X' : 'O'; // Display X or O
};

const swapTurns = () => {
isCircleTurn = !isCircleTurn;
};

const setBoardHoverClass = () => {
board.classList.remove('x');
board.classList.remove('circle');
if (isCircleTurn) {
board.classList.add('circle');
} else {
board.classList.add('x');
}
};

const checkWin = (currentClass) => {
return WINNING_COMBINATIONS.some(combination => {
return combination.every(index => {
return cells[index].classList.contains(currentClass);
});
});
};

startGame();

restartButton.addEventListener('click', startGame);
59 changes: 59 additions & 0 deletions Games/Tic_Tac_Toe_Neon/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #000;
color: #fff;
font-family: Arial, sans-serif;
margin: 0;
}

.game-container {
text-align: center;
}

h1 {
color: #00ffcc;
text-shadow: 0 0 10px #00ffcc, 0 0 20px #00ffcc;
}

#game-board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: repeat(3, 100px);
gap: 10px;
margin: 20px auto;
}

.cell {
width: 100px;
height: 100px;
background-color: #1a1a1a;
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
cursor: pointer;
box-shadow: 0 0 20px #00ffcc;
transition: background-color 0.3s;
}

.cell:hover {
background-color: #333;
}

button {
padding: 10px 20px;
font-size: 1rem;
color: #00ffcc;
background-color: #000;
border: 2px solid #00ffcc;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
}

button:hover {
background-color: #00ffcc;
color: #000;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ This repository also provides one such platforms where contributers come over an
|[Quest_For_Riches](https://github.com/kunjgit/GameZone/tree/main/Games/Quest_For_Riches)|

| [IKnowYou-Mind-Reading-Game](https://github.com/kunjgit/GameZone/tree/main/Games/IKnowYou-Mind-Reading-Game) |
| [Tic_Tac_Toe_Neon](https://github.com/kunjgit/GameZone/tree/main/Games/Tic_Tac_Toe_Neon) |
</center>

<br>
Expand Down
Binary file added assets/images/Tic_Tac_Toe_Neon.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading