0% found this document useful (0 votes)
6 views

complex JavaScript (Web UI using HTML Canvas)

The document is an HTML code for a Tic Tac Toe game that uses a canvas for rendering the game board. It includes JavaScript functions to draw the board and check for a winner. The game allows two players to take turns placing their marks on a 3x3 grid.

Uploaded by

fukreedits
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

complex JavaScript (Web UI using HTML Canvas)

The document is an HTML code for a Tic Tac Toe game that uses a canvas for rendering the game board. It includes JavaScript functions to draw the board and check for a winner. The game allows two players to take turns placing their marks on a 3x3 grid.

Uploaded by

fukreedits
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<!

DOCTYPE html>
<html>
<head>
<title>Tic Tac Toe</title>
<style>
canvas { background: #eee; margin-top: 20px; display: block; margin: auto; }
</style>
</head>
<body>
<canvas id="game" width="300" height="300"></canvas>
<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const size = 100;
let board = [["", "", ""], ["", "", ""], ["", "", ""]];
let current = "X";

function drawBoard() {
ctx.clearRect(0, 0, 300, 300);
for (let i = 1; i < 3; i++) {
ctx.beginPath();
ctx.moveTo(i * size, 0);
ctx.lineTo(i * size, 300);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i * size);
ctx.lineTo(300, i * size);
ctx.stroke();
}
for (let r = 0; r < 3; r++)
for (let c = 0; c < 3; c++) {
let val = board[r][c];
if (val) {
ctx.font = "60px Arial";
ctx.fillText(val, c * size + 30, r * size + 70);
}
}
}

function checkWinner() {
for (let i = 0; i < 3; i++) {
if (board[i][0] && board[i][0] == board[i][1] && board[i][1] == board[i][2])
return board[i][0];
if (board

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy