Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Added calculator . #149

Closed
wants to merge 2 commits into from
Closed
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
Binary file added TicTacToe/image/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions TicTacToe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<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>TicTacToe</title>
<link rel="stylesheet" href="style.css">



<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;1,200&display=swap"
rel="stylesheet">
</head>

<body>


<div class="wrapper">
<h1 class="app-name">Tic Tac Toe</h1>

<div class="game-info">

</div>


<div class="game">
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
<div class="box box-4"></div>
<div class="box box-5"></div>
<div class="box box-6"></div>
<div class="box box-7"></div>
<div class="box box-8"></div>
<div class="box box-9"></div>
</div>


<button class="new-game-btn">New Game</button>

</div>


<script src="script.js"></script>
</body>

</html>
103 changes: 103 additions & 0 deletions TicTacToe/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const gameInfo = document.querySelector('.game-info');
const boxes = document.querySelectorAll('.box');
const newGameBtn = document.querySelector('.new-game-btn');


let currentPlayer;

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

let gameGrid;



function initGame() {
currentPlayer = 'x';
gameGrid = ["", "", "", "", "", "", "", "", ""];

boxes.forEach((box, index) => {
box.innerText = "";
box.style.pointerEvents = "all";
box.classList.remove("win");
});

gameInfo.innerText = `Current Player - ${currentPlayer.toUpperCase()}`;
newGameBtn.classList.remove("active");
}

initGame();



boxes.forEach((box, index) => {
box.addEventListener('click', () => {
handleClick(index);
});
});

function handleClick(index) {
if (gameGrid[index] === "") {
boxes[index].innerText = currentPlayer.toUpperCase();
boxes[index].style.pointerEvents = "none";
gameGrid[index] = currentPlayer;
swapTurn();
checkGameOver();
}
}


function swapTurn() {
currentPlayer = currentPlayer === 'x' ? 'o' : 'x';
gameInfo.innerText = `Current Player - ${currentPlayer.toUpperCase()}`;
}

function checkGameOver() {
let winner = "";
winningPositions.forEach((position) => {
if (gameGrid[position[0]] != "" &&
gameGrid[position[1]] != "" &&
gameGrid[position[2]] != "" &&
gameGrid[position[0]] === gameGrid[position[1]] &&
gameGrid[position[1]] === gameGrid[position[2]]
) {
boxes.forEach((box) => {
box.style.pointerEvents = "none";
});

winner = gameGrid[position[0]] === 'x' ? 'x' : 'o';
boxes[position[0]].classList.add("win");
boxes[position[1]].classList.add("win");
boxes[position[2]].classList.add("win");
}
});

if (winner != "") {
gameInfo.innerText = `Winner - ${winner.toUpperCase()}`;
newGameBtn.classList.add("active");
return;
}


let allBoxesFilled = true;
gameGrid.forEach((box) => {
if (box === "") {
allBoxesFilled = false;
}
});

if (allBoxesFilled) {
gameInfo.innerText = `It's a Draw`;
newGameBtn.classList.add("active");
}
}

newGameBtn.addEventListener('click', initGame);
126 changes: 126 additions & 0 deletions TicTacToe/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}

:root {
--white: #fff;
--black: #000;
--border-clr: rgba(255, 255, 255, 0.25);
--bg-clr: rgba(255, 255, 255, 0.15);
}

html {
font-size: 62.5%;
}

body {
font-size: 1.6rem;
}

.wrapper {
width: 100vw;
min-height: 100vh;
color: var(--white);
background-image: linear-gradient(to right, #fc5c7d, #6a82fb);
display: grid;
place-items: center;
align-items: start;
}

.app-name {
font-size: 4.5rem;
align-self: center;
padding-bottom: 3rem;
}


.game-info {
border: 1px solid var(--border-clr);
padding: 0.8rem 4.8rem;
border-radius: 1.6rem;
background-color: var(--bg-clr);
backdrop-filter: blur(7px);
}

.game {
width: 90%;
max-width: 32rem;
aspect-ratio: 1/1;
background-color: var(--bg-clr);
border: 1px solid var(--border-clr);
border-radius: 1.6rem;
backdrop-filter: blur(7px);
display: grid;
grid-template-columns: repeat(3, 1fr);
padding: 3.2rem;
}

.box {
width: 100%;
aspect-ratio: 1 / 1;
display: grid;
place-items: center;
font-size: 4.8rem;
cursor: pointer;
transition: all 150ms ease-in-out 0s;
}

.box-1,
.box-2,
.box-4,
.box-5 {
border-bottom: 2px solid var(--white);
border-right: 2px solid var(--white);
}

.box-3,
.box-6 {
border-bottom: 2px solid var(--white);
}

.box-7,
.box-8 {
border-right: 2px solid var(--white);
}

/* new game button */
.new-game-btn {
color: var(--white);
background-color: var(--bg-clr);
border: none;
border: 1px solid var(--border-clr);
border-radius: 1.6rem;
padding: 0.8rem 3.2rem;
backdrop-filter: blur(7px);
cursor: pointer;
opacity: 0;
visibility: hidden;
pointer-events: none;
text-transform: capitalize;
transition: all 150ms ease-in-out;
}

.new-game-btn.active {
opacity: 1;
visibility: visible;
pointer-events: all;
}

.win {
background-color: rgba(0, 255, 0, 0.3);
}

@media (max-width: 350px) {
.box {
font-size: 4rem;
}

.app-name {
font-size: 3.5rem;
}
}
44 changes: 44 additions & 0 deletions calculator2/calci.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.container1 {
text-align: center;
margin-top: 23px;
}

table {
margin: auto;
border-collapse: collapse;
}

input {
border-radius: 10px;
font-size: 24px;
height: 50px;
width: 250px;
padding: 5px;
border: 1px solid #ccc;
margin-bottom: 10px;
}

button {
border-radius: 10px;
font-size: 20px;
background: #4CAF50;
color: #fff;
width: 60px;
height: 60px;
margin: 6px;
cursor: pointer;
transition: background 0.3s ease;
}

button:hover {
background: #45a049;
transform: scale(1.05);
}

.calculator {
background-color: #34495E;
padding: 20px;
border-radius: 20px;
display: inline-block;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
62 changes: 62 additions & 0 deletions calculator2/calci.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!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="calci.css">
<title>Calculator</title>
</head>

<body>
<div class="container1 ">





<h1>Simple Calculator</h1>


<div class="calculator">
<input type="text" name="screen" id="display">
<table>
<tr>
<td><button>(</button></td>
<td><button>)</button></td>
<td><button>C</button></td>
<td><button>=</button></td>
</tr>
<tr>
<td><button>9</button></td>
<td><button>8</button></td>
<td><button>7</button></td>
<td><button>+</button></td>
</tr>
<tr>
<td><button>6</button></td>
<td><button>5</button></td>
<td><button>4</button></td>
<td><button>-</button></td>
</tr>
<tr>
<td><button>3</button></td>
<td><button>2</button></td>
<td><button>1</button></td>
<td><button>X</button></td>
</tr>
<tr>
<td><button>0</button></td>
<td><button>.</button></td>
<td><button>%</button></td>
<td><button>/</button></td>
</tr>
</table>
</div>
</div>

</body>
<script src="calci.js"></script>

</html>
Loading