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

sadhika tadinada PR 3 #2826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions Art/sadhikatadinada-tictactoe/index.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS Not accepted in contribution

As the README.md states - we do not accept contribution using JS
The contribution should only be about an animation / creative animation without any logic or use of third part library to handle css

Observing what you have here:
What you could do is using CSS to animate all cells to show a tic tac toe round.
Using css timers to delay cells if needed.

Either close this PR / either adjust this PR so it does not use ANY JS

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!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="styles.css">
</head>
<body>
<div class="container">
<h1>Tic Tac Toe</h1>
<div class="grid" id="grid">
<div class="cell" data-index="0"></div>
<div class="cell" data-index="1"></div>
<div class="cell" data-index="2"></div>
<div class="cell" data-index="3"></div>
<div class="cell" data-index="4"></div>
<div class="cell" data-index="5"></div>
<div class="cell" data-index="6"></div>
<div class="cell" data-index="7"></div>
<div class="cell" data-index="8"></div>
</div>
<button class="reset-btn" onclick="resetGame()">Reset Game</button>
</div>

<script>
const cells = document.querySelectorAll('.cell');
let currentPlayer = 'X';
let board = ['', '', '', '', '', '', '', '', ''];

cells.forEach(cell => {
cell.addEventListener('click', () => {
const index = cell.getAttribute('data-index');

if (board[index] === '' && !checkWinner()) {
board[index] = currentPlayer;
cell.classList.add(currentPlayer.toLowerCase());
cell.textContent = currentPlayer;
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
}

if (checkWinner()) {
setTimeout(() => alert(`${currentPlayer === 'X' ? 'O' : 'X'} wins!`), 100);
}
});
});

function checkWinner() {
const winningCombinations = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];

return winningCombinations.some(combination => {
const [a, b, c] = combination;
return board[a] && board[a] === board[b] && board[a] === board[c];
});
}

function resetGame() {
board = ['', '', '', '', '', '', '', '', ''];
currentPlayer = 'X';
cells.forEach(cell => {
cell.textContent = '';
cell.classList.remove('x', 'o');
});
}
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions Art/sadhikatadinada-tictactoe/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"artName": "Tic Tac Toe",
"githubHandle": "sadhikatadinada"
}
97 changes: 97 additions & 0 deletions Art/sadhikatadinada-tictactoe/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #111; /* Dark background */
font-family: 'Arial', sans-serif;
}

.container {
text-align: center;
}

h1 {
color: #fff;
margin-bottom: 20px;
}

.grid {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: repeat(3, 100px);
gap: 10px;
}

.cell {
width: 100px;
height: 100px;
background-color: #222; /* Dark cell background */
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
position: relative;
}

.cell:hover {
background-color: #333; /* Slightly lighter on hover */
}

.cell.x {
color: #ff4d4d; /* Neon red */
animation: neon-x 0.5s forwards; /* X animation */
}

.cell.o {
color: #4dff4d; /* Neon green */
animation: neon-o 0.5s forwards; /* O animation */
}

@keyframes neon-x {
0% {
text-shadow: 0 0 5px #ff4d4d, 0 0 10px #ff4d4d, 0 0 15px #ff4d4d;
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}

@keyframes neon-o {
0% {
text-shadow: 0 0 5px #4dff4d, 0 0 10px #4dff4d, 0 0 15px #4dff4d;
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}

.reset-btn {
margin-top: 20px;
padding: 10px 20px;
font-size: 1rem;
background-color: #ffcc00;
border: none;
cursor: pointer;
}

.reset-btn:hover {
background-color: #ffd700;
}