Code Monkey home page Code Monkey logo
<title>XOXO Game</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .game { display: grid; grid-template-columns: repeat(3, 100px); grid-template-rows: repeat(3, 100px); gap: 10px; border: 2px solid #000; padding: 10px; background-color: #fff; } .cell { width: 100px; height: 100px; border: 1px solid #000; display: flex; justify-content: center; align-items: center; font-size: 24px; font-weight: bold; cursor: pointer; } .cell:hover { background-color: #ddd; } .game-over { background-color: rgba(255, 0, 0, 0.5); } </style>
<script> const cells = []; const gameOver = () => { for (let i = 0; i < 3; i++) { if (cells[i * 3].textContent === cells[i * 3 + 1].textContent && cells[i * 3].textContent === cells[i * 3 + 2].textContent && cells[i * 3].textContent !== '') { return true; } if (cells[i].textContent === cells[i + 3].textContent && cells[i].textContent === cells[i + 6].textContent && cells[i].textContent !== '') { return true; } } if (cells[0].textContent === cells[4].textContent && cells[0].textContent === cells[8].textContent && cells[0].textContent !== '') { return true; } if (cells[2].textContent === cells[4].textContent && cells[2].textContent === cells[6].textContent && cells[2].textContent !== '') { return true; } return false; }; const draw = () => { for (let i = 0; i < 9; i++) { if (cells[i].textContent === '') { return false; } } return true; }; const resetGame = () => { for (let i = 0; i < 9; i++) { cells[i].textContent = ''; } }; const handleCellClick = (cell) => { if (cell.textContent === '') { cell.textContent = 'X'; if (gameOver()) { document.querySelector('.game').classList.add('game-over'); } else if (draw()) { alert('Draw!'); resetGame(); } else { cell.textContent = 'O'; if (gameOver()) { document.querySelector('.game').classList.add('game-over'); } else if (draw()) { alert('Draw!'); resetGame(); } } } }; const createGame = () => { const game = document.querySelector('.game'); for (let i = 0; i < 9; i++) { const cell = document.createElement('div'); cell.classList.add('cell'); cell.textContent = ''; cell.addEventListener('click', () =>

Kennyblack92's Projects

Kennyblack92 doesnโ€™t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.