Tic Tac Toe Game code | Mini Game In Html, CSS, JS | #untoldCoding

 Tic Tac Toe  Game code | Mini Game In Html, CSS, JS | #untoldCoding

Welcome to another #UntoldCoding adventure! Today we dive into the world of game development with the classic and timeless game – Tic Tac Toe. This little game project will be built using the web development trifecta: HTML, CSS, and JavaScript. Whether you are a beginner looking to hone your skills or an experienced coder looking for a fast and fun project, this Tic Tac Toe game is perfect for you.


Setting up the platform: HTML

Let’s start by using HTML to program our game. Open your favorite code editor and create a new HTML file. Here’s a simple start:




Step 1 Html Code :



<!DOCTYPE html>: Declares the document type and version of the HTML (in this case HTML5).

<html lang="en">: The main component of an HTML document embedded in English.
The first link tag imports the 700-weight Relayway font from Google Fonts.
The second link tag links to an external style document named "style.css" to apply additional styles to HTML elements.
Create an object with the class "untoldcoding" with nine buttons representing the Tic Tac Toe board. These buttons have a class called "button-option".
At the bottom of the board is a "Restart" button with the id "restart".
The HTML code provided is a simple web page for the Tic Tac Toe mini-game. This includes responsive design meta tags, titles, links to external fonts and style sheets, and the body part of the game board where the game board buttons are represented by buttons in a container, and a "Restart" at the bottom of the board There is a bottom. In addition, a hidden category popup container is defined, with a message paragraph and a "new game" button. The script tag goes to an external JavaScript file, possibly enabling the game to work. Overall, this HTML code is the design foundation for a responsive Tic Tac Toe game with associated styling and scripting.

Step 2 CSS Code:




Step 3 JS Code:




btnRef: Represents all buttons on the Tic Tac Toe board.
popupRef: Represents the popup element.
newgameBtn and restartBtn: Represents the buttons to start a new game and restart the current game.
msgRef: Represents the message element.
xTurn: Boolean indicating whether X is currently in turn. It starts as true, indicating that X comes first.
count: Stores the number of transactions in the game.
disableButtons(): Disables all buttons and shows a popup.
enableButtons(): Enables all buttons and hides the popup.
winFunction(letter): Displays a message indicating the winner (X or O) and calls disableButtons().
drawFunction(): Shows a message that creates a draw and calls disableButtons().
Overall, this code is a functional Tic Tac Toe game with user interface, win recognition and pull recognition. Game logic is activated through the click of a button, and the setting is updated accordingly. Popups are used to display win or draw messages, allowing players to start a new game or restart the current one.

Join us on Telegram : Click here.

Join with us YouTube : Click here.

Join with us Instagram: Click here.


Frequently Asked Questions (FAQ) - Tic Tac Toe Mini Game


1. What is this little game about?
This little game is a simplified version of the classic Tic Tac Toe. Players take turns placing their markers (X or O) on a 3x3 grid, aiming to make knots out of three of those markers.

2. How can I play the game?
Click on the empty button to place your marker (X or O). The goal is to get your three marker scores horizontal, vertical, or horizontal.

3. How can I restart the game?
You can restart the game by pressing the "Restart" button at the bottom of the game board.

4. What happens if the game ends in a draw?
If all the buttons are pressed, and no one wins, the game is declared a draw. You will see a message that you have drawn and you can start a new game.

5. How can I start a new game?
When the game ends (whether it's a win or a draw), a pop-up message will appear with a "new game" button. Pressing this button will reset the game and allow you to start a new one.

6. Can I play this game on a mobile device?
Yes, the game is designed to be compatible, allowing you to play on devices including mobile phones and tablets.

7. What do messages in popups mean?
The message in the popup tells you whether a player won and whether a player (X or O) won. A failure to draw would mean the end of the game.

8. Can I customize the look of the game?
Yes, you can customize the look of the game by editing the associated CSS file ("style.css"). Feel free to customize colors, fonts, and other accessories.

9. Where can I find the source code for this game?
The source code for this Tic Tac Toe mini-game is contained in external files, including "style.css" for styling and "script.js" for scripting. You can search and edit the code .

No comments

Powered by Blogger.