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 Tic Tac Toe Project #403

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
208 changes: 110 additions & 98 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,118 +290,130 @@ <h3 class="card__heading">Clothing Shop</h3>
</div>
</a>

<a class="card" href="projects/Tic_Tac_Toe/index.html">

<a class="card" href="projects/Tic_Tac_Toe/index.html">
<div class="card__background" style="background-image: url(projects/Tic_Tac_Toe/images/tic_tac_toe.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Tic Tac Toe</h3>


<a class="card" href="projects/Bing/index.html">
<div class="card__background" style="background-image: url(projects/Bing/images/preview.jpg)"></div>
<div class="card__content">
<p class="card__category">Bing</p>
<h3 class="card__heading">Top 10 rated Netflix Series of 2023</h3>
</div>
</a>
<a class="card" href="projects/Candy_Crush/index.html">
<div class="card__background" style="background-image: url(projects/Candy_Crush/candy-crush-background-2.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Candy Crush</h3>
</div>
</a>


<a class="card" href="projects/Bing/index.html">
<div class="card__background" style="background-image: url(projects/Bing/images/preview.jpg)"></div>
<div class="card__content">
<p class="card__category">Bing</p>
<h3 class="card__heading">Top 10 rated Netflix Series of 2023</h3>
</div>
</a>
<a class="card" href="projects/Candy_Crush/index.html">
<div class="card__background"
style="background-image: url(projects/Candy_Crush/candy-crush-background-2.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Candy Crush</h3>
</div>
</a>



<a class="card" href="projects/Memory_Game/index.html">
<div class="card__background" style="background-image: url(projects/Memory_Game/images/preview.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Memory Game</h3>
</div>
</a>

<a class="card" href="projects/college/index.html">
<div class="card__background" style="background-image: url(projects/college/images/background.jpg)"></div>
<div class="card__content">
<p class="card__category">Website</p>
<h3 class="card__heading">University Website</h3>
</div>
</a>

<a class="card" href="projects/Expense_Tracker/index.html">
<div class="card__background" style="background-image: url(projects/Expense_Tracker/download.png)"></div>
<div class="card__content">
<p class="card__category">Expense_Tracker/p>
<h3 class="card__heading">Expense Tracker</h3>
</div>
</a>

<a class="card" href="projects/Spotify_Clone/index.html">
<div class="card__background" style="background-image: url(projects/Spotify_Clone/images/prew.jpg)"></div>
<div class="card__content">
<p class="card__category">Clone/p>
<h3 class="card__heading">Spotify Clone</h3>
</div>
</a>

<a class="card" href="projects/Solar_System_Model/index.html">
<div class="card__background" style="background-image: url(projects/Solar_System_Model/Screenshot.png)">
</div>
<div class="card__content">
<p class="card__category">Website</p>
<h3 class="card__heading">Solar System Model</h3>
</div>
</a>



<a class="card" href="projects/Bingo_Game/index.html">
<div class="card__background" style="background-image: url(projects/Bingo_Game/images/Bingo_Game.png)">
</div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Bingo Game</h3>

</div>
</a>
<a class="card" href="projects/Tic-Tac-Toe/index.html">
<div class="card__background" style="background-image: url(projects/Tic-Tac-Toe/sample.jpg)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Bingo Game</h3>

</div>
</a>

<div>
</section>

<a class="card" href="projects/Memory_Game/index.html">
<div class="card__background" style="background-image: url(projects/Memory_Game/images/preview.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Memory Game</h3>
</div>
</a>

<a class="card" href="projects/college/index.html">
<div class="card__background" style="background-image: url(projects/college/images/background.jpg)"></div>
<div class="card__content">
<p class="card__category">Website</p>
<h3 class="card__heading">University Website</h3>
</div>
</a>

<a class="card" href="projects/Expense_Tracker/index.html">
<div class="card__background" style="background-image: url(projects/Expense_Tracker/download.png)"></div>
<div class="card__content">
<p class="card__category">Expense_Tracker/p>
<h3 class="card__heading">Expense Tracker</h3>
</div>
<!-- Footer Section Starts -->
<div class="section">
<h3>CONTACT <span>US</span></h3>
<div class="wrapper">
<a href="https://www.youtube.com/channel/UCytURJu5gyXDvJB3axWGFzQ" target="_blank" class="icon facebook">
<div class="tooltip">YouTube</div>
<span><i class="fab fa-youtube" style="font-size:48px"></i></span>
</a>

<a class="card" href="projects/Spotify_Clone/index.html">
<div class="card__background" style="background-image: url(projects/Spotify_Clone/images/prew.jpg)"></div>
<div class="card__content">
<p class="card__category">Clone/p>
<h3 class="card__heading">Spotify Clone</h3>
</div>
<a href="https://www.facebook.com/SSITVIT/" target="_blank" class="icon twitter">
<div class="tooltip">Facebook</div>
<span><i class="fab fa-facebook" style="font-size:48px"></i></span>
</a>

<a class="card" href="projects/Solar_System_Model/index.html">
<div class="card__background" style="background-image: url(projects/Solar_System_Model/Screenshot.png)"></div>
<div class="card__content">
<p class="card__category">Website</p>
<h3 class="card__heading">Solar System Model</h3>
</div>
<a href="https://www.instagram.com/ieeessit/" target="_blank" class="icon instagram">
<div class="tooltip">Instagram</div>
<span><i class="fa fa-instagram" style="font-size:48px"></i></span>
</a>



<a class="card" href="projects/Bingo_Game/index.html">
<div class="card__background" style="background-image: url(projects/Bingo_Game/images/Bingo_Game.png)"></div>
<div class="card__content">
<p class="card__category">Game</p>
<h3 class="card__heading">Bingo Game</h3>

</div>
<a href="https://github.com/ssitvit" target="_blank" class="icon github">
<div class="tooltip">Github</div>
<span><i class="fab fa-github" style="font-size:48px"></i></span>
</a>

<div>
</section>

<!-- Footer Section Starts -->
<div class="section"><h3>CONTACT <span>US</span></h3>
<div class="wrapper">
<a href="https://www.youtube.com/channel/UCytURJu5gyXDvJB3axWGFzQ" target="_blank" class="icon facebook">
<div class="tooltip">YouTube</div>
<span><i class="fab fa-youtube" style="font-size:48px"></i></span>
</a>
<a href="https://www.facebook.com/SSITVIT/" target="_blank" class="icon twitter">
<div class="tooltip">Facebook</div>
<span><i class="fab fa-facebook" style="font-size:48px"></i></span>
</a>
<a href="https://www.instagram.com/ieeessit/" target="_blank" class="icon instagram">
<div class="tooltip">Instagram</div>
<span><i class="fa fa-instagram" style="font-size:48px"></i></span>
</a>
<a href="https://github.com/ssitvit" target="_blank" class="icon github">
<div class="tooltip">Github</div>
<span><i class="fab fa-github" style="font-size:48px"></i></span>
</a>
<a href="https://www.linkedin.com/company/ieee-ssit-vit/" class="icon linkedin">
<div class="tooltip">Linkedin</div>
<span><i class="fab fa-linkedin" style="font-size:45px"></i></span>
</a>
</div>
<hr>
<div>
<div class="footer-copyright">
<h4>IEEE SSIT VIT © 2023</h4>
</div>
<a href="https://www.linkedin.com/company/ieee-ssit-vit/" class="icon linkedin">
<div class="tooltip">Linkedin</div>
<span><i class="fab fa-linkedin" style="font-size:45px"></i></span>
</a>
</div>
<hr>
<div>
<div class="footer-copyright">
<h4>IEEE SSIT VIT © 2023</h4>
</div>
</div>
</div>
<!-- Footer Section Ends -->
<script src="filter_project.js"></script>
<script src="script.js"></script>

</body>
</body>
31 changes: 31 additions & 0 deletions projects/Tic-Tac-Toe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./style.css">
<title>Document</title>
</head>

<body>
<div class="board" id="board">
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
<div class="cell" data-cell></div>
</div>
<div class="winning-message" id="winningMessage">
<div data-winning-message-text></div>
<button id="restartButton">Restart</button>
</div>
<script src="./index.js"></script>
</body>

</html>
89 changes: 89 additions & 0 deletions projects/Tic-Tac-Toe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const X_CLASS = 'x'
const CIRCLE_CLASS = 'circle'
const WINNING_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
]
const cellElements = document.querySelectorAll('[data-cell]')
const board = document.getElementById('board')
const winningMessageElement = document.getElementById('winningMessage')
const restartButton = document.getElementById('restartButton')
const winningMessageTextElement = document.querySelector('[data-winning-message-text]')
let circleTurn

startGame()

restartButton.addEventListener('click', startGame)

function startGame() {
circleTurn = false
cellElements.forEach(cell => {
cell.classList.remove(X_CLASS)
cell.classList.remove(CIRCLE_CLASS)
cell.removeEventListener('click', handleClick)
cell.addEventListener('click', handleClick, { once: true })
})
setBoardHoverClass()
winningMessageElement.classList.remove('show')
}

function handleClick(e) {
const cell = e.target
const currentClass = circleTurn ? CIRCLE_CLASS : X_CLASS
placeMark(cell, currentClass)
if (checkWin(currentClass)) {
endGame(false)
} else if (isDraw()) {
endGame(true)
} else {
swapTurns()
setBoardHoverClass()
}
}

function endGame(draw) {
if (draw) {
winningMessageTextElement.innerText = 'Draw!'
} else {
winningMessageTextElement.innerText = `${circleTurn ? "O's" : "X's"} Wins!`
}
winningMessageElement.classList.add('show')
}

function isDraw() {
return [...cellElements].every(cell => {
return cell.classList.contains(X_CLASS) || cell.classList.contains(CIRCLE_CLASS)
})
}

function placeMark(cell, currentClass) {
cell.classList.add(currentClass)
}

function swapTurns() {
circleTurn = !circleTurn
}

function setBoardHoverClass() {
board.classList.remove(X_CLASS)
board.classList.remove(CIRCLE_CLASS)
if (circleTurn) {
board.classList.add(CIRCLE_CLASS)
} else {
board.classList.add(X_CLASS)
}
}

function checkWin(currentClass) {
return WINNING_COMBINATIONS.some(combination => {
return combination.every(index => {
return cellElements[index].classList.contains(currentClass)
})
})
}
Binary file added projects/Tic-Tac-Toe/sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading