Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TicTacToe Game #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ This repository contains a collection of frontend projects.Each project is built
<td>Bubble Game</td>
<td><a href="./project-20_bubble_game">Click Here</a></td>
</tr>
<tr>
<td>21</td>
<td>Tic Tac Toe Game</td>
<td><a href="./project-21_TicTacToe_Game">Click Here</a></td>
</tr>
</table>


Expand Down
Binary file added project-21_TicTacToe_Game/circle.png
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 project-21_TicTacToe_Game/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions project-21_TicTacToe_Game/game.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
*{
background-color: rgb(1, 1, 54);
margin: 0px;
padding: 0px;
justify-content: center;
}

.heading{
margin-top: 20px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: bolder;
color: white;
text-shadow:
0 0 5px #ff00ff,
0 0 10px #ff00ff,
0 0 15px #ff00ff;
font-size: 60px;
}

p{
color: white;
font-family: Poppins;
text-align: center;
margin-top: 10px;
font-size: 20px;
}

.container{
width: 420px;
border-radius: 10px;
display: flex;
flex-wrap: wrap;
margin-top: 30px;
background-color: white;
filter: drop-shadow(0px 0px 5px #ff00ff);
}

.box{
height: 130px;
width: 130px;
border: none;
background-color: rgb(1, 1, 54);
margin: 5px;
border-radius: 10px;
filter: drop-shadow(0px 0px 5px #ff00ff);
color: white;
font-size: 80px;
}

.box:hover{
cursor: pointer;
}

.msg{
height: 50px;
width: auto;
margin-top: 15px;
margin-bottom: 15px;
font-size: 50px;
font-family: Poppins;
font-weight: 900;
color: white;
}

.play button{
padding: 10px;
width: 200px;
margin: 30px;
border: 0px solid black;
border-radius: 10px;
color: white;
font-family: Poppins;
font-size: 20px;
box-shadow:
0 0 10px #ff00ff;
}

.play button:hover{
cursor: pointer;
background-color: white;
color: #ff00ff;
}

.hide{
display: none;
}
37 changes: 37 additions & 0 deletions project-21_TicTacToe_Game/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic Tac Toe</title>
</head>
<link rel="stylesheet" href="game.css">

<body>
<div class="heading"><center>Tic Tac Toe</center></div>
<p>'X' plays first!</p>
<center><div class="container">
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
<button class="box"></button>
</div></center>

<div class="msg-container hide">
<center><div class="msg">
Winner
</div></center>

<center><div class="play">
<a href="game.html"><button id="again">Play Again</button></a>
<a href="index.html"><button>Main Menu</button></a>
</div></center>
</div>
<script src="game.js"></script>
</body>
</html>
54 changes: 54 additions & 0 deletions project-21_TicTacToe_Game/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
let boxes = document.querySelectorAll(".box");
let newGame = document.querySelector("#again");
let msgContainer = document.querySelector(".msg-container");
let msg = document.querySelector(".msg");

let turnx = true;

const winPatterns = [
[0, 1, 2],
[0, 3, 6],
[0, 4, 8],
[1, 4, 7],
[2, 5, 8],
[2, 4, 6],
[3, 4, 5],
[6, 7, 8]
]

const showWinner = (wplayer) => {
msg.innerText = `Congratulations! Winner: ${wplayer}`;
msgContainer.classList.remove("hide");
}

const winner = () => {
for(pattern of winPatterns){
let p1 = boxes[pattern[0]].innerText;
let p2 = boxes[pattern[1]].innerText;
let p3 = boxes[pattern[2]].innerText;

if(p1!="" && p2!="" && p3!=""){
if(p1==p2 && p2==p3){
showWinner(p1);
}
}
}
}

boxes.forEach((box) => {
box.addEventListener("click", () => {
if (box.textContent == "") {
if (turnx) {
box.textContent = "X";
turnx = false;
}
else {
box.textContent = "O";
turnx = true;
}
box.disabled=true;

winner();
}
})
})
115 changes: 115 additions & 0 deletions project-21_TicTacToe_Game/human.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
*{
background-color: rgb(1, 1, 54);
margin: 0px;
padding: 0px;
justify-content: center;
}

.heading{
margin-top: 20px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: bolder;
color: white;
text-shadow:
0 0 5px #ff00ff,
0 0 10px #ff00ff,
0 0 15px #ff00ff;
font-size: 60px;
}

.heading a{
text-decoration: none;
color: white;
}

.players{
color: white;
font-family: Poppins;
font-size: 20px;
margin-top: 30px;
}

.players input{
margin: 20px;
padding: 5px;
height: 20px;
width: 200px;
border: 1px solid white;
border-radius: 5px;
color: white;
}

.choose{
display: flex;
flex-direction: row;
margin: 20px;
margin-top: 50px;
}

.cross img{
margin-top: 20px;
height: 150px;
width: 150px;
}

.cross{
height: 150px;
width: 150px;
margin-right: 100px;
color: white;
font-size: x-large;
font-family: Poppins;
text-align: center;
}

.swap{
color: white;
font-family: Poppins;
text-align: center;
}

.swap img{
height: 100px;
width: 100px;
margin-top: 75px;
}

.swap img:hover{
cursor: pointer;
}

.circle{
height: 150px;
width: 150px;
margin-left: 100px;
color: white;
font-size: x-large;
font-family: Poppins;
text-align: center;
}

.circle img{
margin-top: 20px;
height: 150px;
width: 150px;
}

#play{
margin-top: 40px;
width: 150px;
padding: 15px;
border: 0px solid black;
border-radius: 10px;
color: white;
font-family: Poppins;
font-size: 30px;
font-weight: bolder;
box-shadow:
0 0 10px #ff00ff;
}

#play:hover{
cursor: pointer;
background-color: white;
color: #ff00ff;
}
39 changes: 39 additions & 0 deletions project-21_TicTacToe_Game/human.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic Tac Toe</title>
</head>
<link rel="stylesheet" href="human.css">

<body>
<div class="heading"><a href="index.html"><center>Tic Tac Toe</center></a></div>

<form target="game.html">
<div class="players"><center>
Player 1: <input type="text" id="p1" required><br>
Player 2: <input type="text" id="p2" required>
</center></div>


<div class="choose">
<div class="cross">
Player 1
<img src="cross.png" id="cross">
</div>
<div class="swap"><img src="swap.png" id="swap"><br>
Swap
</div>
<div class="circle">
Player 2
<img src="circle.png" id="circle">
</div>
</div>

<center><a href="game.html"><button id="play" type="button">Play !</button></a></center>
</form>

<script src="human.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions project-21_TicTacToe_Game/human.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let swapping=document.querySelector("#swap");

swapping.onclick = () => {
const img1 = document.getElementById('cross');
const img2 = document.getElementById('circle');

const temp = img1.src;
img1.src = img2.src;
img2.src = temp;
}
Binary file added project-21_TicTacToe_Game/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading