neon_tictactoe_game = {
({
prompt: "Create a tick tack toe game using neon colors",
time: 1699470230338,
comment: "Creating a tic-tac-toe game with neon colors"
});
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
canvas.width = 300;
canvas.height = 300;
const cellSize = 100;
let board = Array(3)
.fill()
.map(() => Array(3).fill(""));
let currentPlayer = "X";
const drawBoard = () => {
context.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i <= 2; i++) {
for (let j = 0; j <= 2; j++) {
context.strokeStyle = "#00FF00";
context.strokeRect(i * cellSize, j * cellSize, cellSize, cellSize);
context.font = "50px sans-serif";
context.fillStyle = currentPlayer === "X" ? "#FF00FF" : "#00FFFF";
context.fillText(
board[i][j],
i * cellSize + cellSize / 3,
j * cellSize + (2 * cellSize) / 3
);
}
}
};
const handleClick = (event) => {
let x = Math.floor(event.offsetX / cellSize);
let y = Math.floor(event.offsetY / cellSize);
if (board[x][y] === "") {
board[x][y] = currentPlayer;
currentPlayer = currentPlayer === "X" ? "O" : "X";
}
drawBoard();
};
canvas.addEventListener("click", handleClick);
drawBoard();
return canvas;
}