Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body style="background-color: black; color: white"> | ||
<input type="text" id="make-input"> | ||
<button id="make-button">Make Something</button> | ||
<ul id="make-list"></ul> | ||
<button onclick="clearAll()">Delete</button> | ||
<script> | ||
const makeButton = document.getElementById('make-button'); | ||
makeButton.addEventListener('click', makeIt); | ||
let makeInput= document.getElementById('make-input'); | ||
|
||
const todolist[]; | ||
|
||
|
||
function makeIt(){ | ||
console.log(makeInput.value); | ||
const newBabyLi = document.createElement('li'); | ||
const makeList = document.getElementById('make-list'); | ||
newBabyLi.innerHTML = makeInput.value; | ||
newBabyLi.addEventListener('click', () =>{ | ||
newBabyLi.remove(); | ||
}); | ||
makeList.appendChild(newBabyLi); | ||
makeInput.value = ''; | ||
}; | ||
|
||
function clearAll() { | ||
while(makeList.hasChildNodes()){ | ||
makeList.removeChild(makeList.lastChild); | ||
} | ||
} | ||
</script> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Tic Tac Toe</title> | ||
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css"> | ||
<link rel="stylesheet" href="tictac.css"> | ||
|
||
</head> | ||
<body> | ||
|
||
<div class="container text-center"> | ||
<div class="turn-display"></div><br> | ||
<div class="row"> | ||
<div class="col md-4 cell" data-index="1"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="2"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="3"> | ||
|
||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col md-4 cell" data-index="4"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="5"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="6"> | ||
|
||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col md-4 cell" data-index="7"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="8"> | ||
|
||
</div> | ||
<div class="col md-4 cell" data-index="9"> | ||
|
||
</div> | ||
</div> | ||
<div class="row"> | ||
<br><br> | ||
<div class="restart"><button id="playAgain" class="btn btn-danger" onclick="playAgain()">Play Again</button></div> | ||
<br> | ||
<br> | ||
<div id="game-result"></div> | ||
</div> | ||
</div> | ||
<br><br> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script> | ||
<script src="node_modules/jquery/dist/jquery.js"></script> | ||
<script src="tictac.js"></script> | ||
|
||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"bootstrap": "^5.3.0", | ||
"jquery": "^3.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
body { | ||
background-color: black; | ||
} | ||
|
||
.cell { | ||
border-radius: 10px; | ||
height: 100px; | ||
width: 100px; | ||
border: 2px solid white; | ||
box-shadow: 1px 1px 10px 10px pink; | ||
color: White; | ||
font-size: 50px; | ||
display: flex; | ||
justify-content: center; | ||
text-shadow: 2px 2px 2px pink; | ||
} | ||
|
||
#game-result{ | ||
color: White; | ||
font-size: 50px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
.turn-display{ | ||
color: White; | ||
font-size: 50px; | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
let currentPlayer= "X"; | ||
let plays = 0; | ||
let gameFinished = false; | ||
let currentPlayed= { | ||
X: [], | ||
O: [], | ||
}; | ||
|
||
const winPositions = [ | ||
[1,2,3], | ||
[4,5,6], | ||
[7,8,9], | ||
[1,4,7], | ||
[2,5,8], | ||
[3,6,9], | ||
[1,5,9], | ||
[3,5,7] | ||
|
||
]; | ||
|
||
$(document).ready(function() { | ||
|
||
// $('.turn-display').text("It is Curently " + currentPlayer + "'s Turn"); | ||
$('.cell').on('click', function() { | ||
|
||
if(!gameFinished){ | ||
$(this).text(currentPlayer); | ||
plays++ | ||
currentPlayed[currentPlayer].push(parseInt($(this).attr('data-index'))); | ||
|
||
if(isWinner()){ | ||
gameFinished = true; | ||
showResult('Win') | ||
}; | ||
if(!gameFinished && isDraw()){ | ||
showResult('Draw'); | ||
} | ||
|
||
currentPlayer = (currentPlayer === "X") ? "O" : "X"; | ||
|
||
$('.turn-display').text("It is Curently " + currentPlayer + "'s Turn"); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
function playAgain(){ | ||
currentPlayer= "X"; | ||
plays = 0; | ||
gameFinished = false; | ||
currentPlayed= { | ||
X: [], | ||
O: [], | ||
}; | ||
$(".cell, #game-result").text(' '); | ||
|
||
}; | ||
|
||
function showResult(type){ | ||
gameFinished = true; | ||
if (type === 'Win'){ | ||
$('#game-result').text('Winner is: ' + currentPlayer); | ||
}else{ | ||
$('#game-result').text('It is a Draw!'); | ||
} | ||
|
||
} | ||
|
||
function isDraw(){ | ||
return plays === 9; | ||
|
||
} | ||
|
||
function isWinner(){ | ||
if (plays < 5) | ||
return; | ||
|
||
for (let i = 0; i < winPositions.length; i++){ | ||
let isWinner = true; | ||
|
||
for(let j=0; j < winPositions[i].length; j++){ | ||
if ($.inArray(winPositions[i][j], currentPlayed[currentPlayer]) < 0){ | ||
isWinner = false; | ||
break; | ||
} | ||
} | ||
if (isWinner) | ||
return true; | ||
|
||
} | ||
} |