Skip to content

Commit

Permalink
Merge pull request #3182 from RazaAli313/main
Browse files Browse the repository at this point in the history
Tic Tac Toe Game
  • Loading branch information
kunjgit authored Jul 27, 2024
2 parents 5bb8016 + 33ad579 commit 01ae10b
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Games/Tic_Tac_Toe_Game/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Tic Tac Toe

## Description 📃
This is a classic Tic Tac Toe game implemented with additional functionalities such as success music on winning, music on game drawn, and sound on each click of turn. The game features a user-friendly interface and supports both single-player and two-player modes.

## Functionalities 🎮
- Play against the another player
- Success music on winning
- Music on game drawn
- Sound on each click of turn
- Recognizes winning combinations horizontally, vertically, and diagonally
- Attractive UI

## How to Play? 🕹️
1. Launch the game.
2. Click on the desired cell to place your symbol (X or O).
3. Alternate turns with your opponent.
4. The first player to achieve three of their symbols in a row wins.
5. If all cells are filled and no player has three symbols in a row, the game is drawn.

## Screenshots 📸

![Tic_Tac_Toe_Game](https://github.com/RazaAli313/GameZone/assets/136004622/bd0b8de4-9c72-4a53-9f38-e01e67057ba5)


## Working Video 📹
Uploading Tic Tac Toe Game.mp4…

Binary file added Games/Tic_Tac_Toe_Game/ding.mp3
Binary file not shown.
Binary file added Games/Tic_Tac_Toe_Game/excited.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Tic_Tac_Toe_Game/gameover.mp3
Binary file not shown.
42 changes: 42 additions & 0 deletions Games/Tic_Tac_Toe_Game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet">
<link rel="shortcut icon" href="tic-tac-toe.png" type="image/x-icon">
<title>Tic Tac Toe Game</title>
</head>
<body>
<nav>
<ul>
<li>My Tic Tac Toe Game</li>
</ul>
</nav>
<div class="gamecontainer">
<div class="container">
<div class="line"></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
<div class="box"><span class="boxtext"></span></div>
</div>
<div class="gameinfo">
<h1>Welcome to Tic Tac Toe</h1>
<div class="info">
<span id="turn">Turn for X</span>
<button id="reset"onclick="func()">Play Again</button>
</div>
<div class="imgbox">
<img src="excited.gif"alt="Congratulations Gif">
</div>
</div>
</div>
<script src="index.js">
</body>
</html>
75 changes: 75 additions & 0 deletions Games/Tic_Tac_Toe_Game/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
console.log("Welcome To Tic Tac Toe Game");

let gameover = false;
let turn_music = new Audio('ding.mp3');
open_game = new Audio('music.mp3');
open_game.play();
let gamesuccess = new Audio('success.mp3');
let gameover_music = new Audio('gameover.mp3');

let turn = 'X';

const changeTurn = () => {
return turn === 'X' ? 'O' : 'X';
}

const checkWin = () => {
box = document.getElementsByClassName("boxtext");
win = [
[0, 1, 2, 5, 5, 0],
[3, 4, 5, 5, 15, 0],
[6, 7, 8, 5, 25, 0],
[0, 3, 6, -5, 15, 90],
[1, 4, 7, 5, 15, 90],
[2, 5, 8, 15, 15, 90],
[0, 4, 8, 5, 15, 45],
[2, 4, 6, 5, 15, 135]
]
win.forEach(e => {
if (box[e[0]].innerText === box[e[1]].innerText && box[e[1]].innerText === box[e[2]].innerText && box[e[0]].innerText !== '') {
document.getElementById("turn").innerText = box[e[0]].innerText + " Won";
gameover = true;
document.querySelector('.imgbox').getElementsByTagName('img')[0].style.display = "block";
gamesuccess.play();
document.querySelector('.line').style.transform = `translate(${e[3]}vw,${e[4]}vw) rotate(${e[5]}deg)`;
document.querySelector('.line').style.display = 'block';
}
});
}

let boxes = document.getElementsByClassName("box");
Array.from(boxes).forEach(element => {
let boxtext = element.querySelector(".boxtext");
element.addEventListener('click', () => {
open_game.pause();
if (boxtext.innerText === '') {
boxtext.innerText = turn;
turn = changeTurn();
turn_music.play();
checkWin();
if (!gameover) {
let isFilled = Array.from(box).every(element => element.innerText !== '');
if (isFilled) {
document.getElementById("turn").innerText = "Game is Over!!!";
gameover_music.play();
}
else {
document.getElementById("turn").innerText = "Turn For " + turn;
}
}
}
});
})

function func() {
let boxes = document.getElementsByClassName("box");
Array.from(boxes).forEach(element => {
element.querySelector(".boxtext").innerText = "";
document.querySelector('.imgbox').getElementsByTagName('img')[0].style.display = "none";
document.getElementById("turn").innerText = "Turn For " + 'X';
open_game.play();
turn = 'X';
document.querySelector('.line').style.display = "none";
gameover = false;
})
}
Binary file added Games/Tic_Tac_Toe_Game/music.mp3
Binary file not shown.
109 changes: 109 additions & 0 deletions Games/Tic_Tac_Toe_Game/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
@import url('https://fonts.googleapis.com/css2?family=Baloo+Bhaina+2:wght@400;500&family=Roboto&display=swap');

*{
margin: 0;
padding: 0;
}
body{
height: 100vh;
width: 100vw;
border-right:7px solid skyblue;
border-left:7px solid skyblue;
border-bottom:7px solid skyblue;
}
nav{
border:7px solid skyblue;
background-color: blueviolet;
color:white;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
}
nav ul li{
font-size: 27px;
font-family:'Roboto', sans-serif;
list-style: none;
}
.gamecontainer{
display: flex;
justify-content: center;
margin-top: 50px;
position: relative;
}
.line{
background-color: rgb(0, 140, 255);
width:20vw;
height: 3px;
position: absolute;
display: none;
}
.imgbox{
display: flex;
justify-content: center;
}
.imgbox img{
height: 30vh;
display: none;
margin-top: 20px;


}
.container{
display: grid;
grid-template-columns:repeat(3,10vw);
grid-template-rows:repeat(3,10vw);
font-family: 'Roboto', sans-serif;
position: relative;
}
.box{
border: 2px solid blueviolet;
font-size: 8vw;
}
.box:hover{
background-color: rgb(234, 221, 246);
cursor: pointer;
}
.boxtext{
display: flex;
justify-content: center;
}
.gameinfo{
padding:0 34px;
font-family:'Baloo Bhaina 2', cursive;
}
.info{
text-align: center;
font-size: 2vh;
}
#reset{
background-color:rgb(156, 96, 212);


font-weight: bold;
color: white;
width: auto;
padding:1vh;
border-radius: 10px;
cursor: pointer;
margin-left: 10px;
}
#turn{
color: gray;
font-size: 2.5vh;
}
@media screen and (max-width:800px) {
.gamecontainer{
flex-wrap: wrap;
}
.gameinfo{
margin-top: 34px;
}
.gameinfo h1{
font-size: 1.5rem;
}
.container{
grid-template-columns:repeat(3,20vw);
grid-template-rows:repeat(3,20vw);
}
}
Binary file added Games/Tic_Tac_Toe_Game/success.mp3
Binary file not shown.
Binary file added Games/Tic_Tac_Toe_Game/tic-tac-toe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,10 @@ This repository also provides one such platforms where contributers come over an
| [Find Extra Cube](https://github.com/kunjgit/GameZone/tree/main/Games/Find_Extra_Cube) | [PathPlex](https://github.com/kunjgit/GameZone/tree/main/Games/Pathplex) | [CSS Select](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Select) | [Squid](https://github.com/kunjgit/GameZone/tree/main/Games/Squid_Game) | [CSS Crossword](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Crossword) |
| [CSS Select](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Select) | [Squid](https://github.com/kunjgit/GameZone/tree/main/Games/Squid_Game) | [Flip Coin](https://github.com/kunjgit/GameZone/tree/main/Games/Flip_Coin) | [Witty Word Quest](https://github.com/kunjgit/GameZone/tree/main/Games/witty_word_quest) | [Typing Game](https://github.com/Ishan-77/GameZone/tree/main/Games/Typing_Game) |
| [numeral-whiz](https://github.com/Ishan-77/GameZone/tree/main/Games/numeral-whiz) | [candy_match](https://github.com/kunjgit/GameZone/tree/main/Games/Candy_Match_Saga) | [Crossy_Road](https://github.com/tanujbordikar/GameZone/tree/Crossy_Road) | [HueHero](https://github.com/kunjgit/GameZone/tree/main/Games/HueHero) | [Puzzel_Winner](https://github.com/kunjgit/GameZone/tree/main/Games/Puzzel_Winner) |
| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | [Pop My Balloon](https://github.com/kunjgit/GameZone/tree/main/Games/Pop_My_Balloon) | [Color_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Color_Blast) |

| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who)
| [Tic Tac Toe](https://github.com/kunjgit/GameZone/tree/main/Games/Tic_Tac_Toe_Game)| | |
| [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | [Pop My Balloon](https://github.com/kunjgit/GameZone/tree/main/Games/Pop_My_Balloon) | [Color_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Color_Blast) |
| [Maze_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Maze_Game) | [Coloron](https://github.com/kunjgit/GameZone/tree/main/Games/Coloron). |
| [Black_jackk](https://github.com/kunjgit/GameZone/tree/main/Games/Black_jackk) | [Audio_Wordle](https://github.com/kunjgit/GameZone/tree/main/Games/Audio_Wordle) | [Makeover_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Makeover_Game)
| [Maze_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Maze_Game) | [Coloron](https://github.com/kunjgit/GameZone/tree/main/Games/Coloron).
Expand Down Expand Up @@ -950,6 +953,7 @@ This repository also provides one such platforms where contributers come over an
| [Bunny is Lost](https://github.com/kunjgit/GameZone/tree/main/Games/Bunny_is_Lost)|
|[Steam_Punk](https://github.com/kunjgit/GameZone/tree/main/Games/Steam_Punk)|


|[OutRun_Offline_Game](https://github.com/kunjgit/GameZone/tree/main/Games/OutRun_Offline_Game)|
|[Tower Defence Game](https://github.com/Will2Jacks/GameZoneForked/tree/Task/Games/Tower_Defence_Game)|

Expand Down
Binary file added assets/images/Tic_Tac_Toe_Game.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 01ae10b

Please sign in to comment.