Skip to content
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
22 changes: 22 additions & 0 deletions 2048 GAME/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function setGame() {
setTwo();
setTwo();

updateProgressBar(score);

}

function updateTile(tile, num) {
Expand Down Expand Up @@ -66,6 +68,8 @@ document.addEventListener('keyup', (e) => {
setTwo();
}
document.getElementById("score").innerText = score;
updateProgressBar();

if(score>=2048){
document.getElementById("won").innerText = "🎉CONGRATULATION'S YOU WON🥳";
}
Expand Down Expand Up @@ -178,4 +182,22 @@ function hasEmptyTile() {
}

return false;
}

function getMaxTile() {
let maxTile = 0;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < columns; c++) {
if (board[r][c] > maxTile) maxTile = board[r][c];
}
}
return maxTile;
}

function updateProgressBar() {
const goal = 2048;
const bar = document.getElementById("progress-bar");
let maxTile = getMaxTile();
let progress = Math.min((maxTile / goal) * 100, 100);
bar.style.width = progress + "%";
}
7 changes: 6 additions & 1 deletion 2048 GAME/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
<body>
<h1>2048</h1>
<p>Created by Chetan Patil</p>
<h2 id="won">"KEEP TRYING- GET 2048 TO WIN"</h2>
<hr>
<h2>Score: <span id="score">0</span></h2>
<h2 id="won">"KEEP TRYING-SCORE 2048 TO WIN"</h2>

<div class="progress-container">
<div id="progress-bar"></div>
</div>

<div id="board">
</div>
<div id="result"></div>
Expand Down
21 changes: 21 additions & 0 deletions 2048 GAME/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ hr {
p{
font-weight: bold;
}


.progress-container {
height: 20px;
width: 80%;
max-width: 400px;
background-color: #dcdcdc;
border-radius: 10px;
margin: 20px auto;
overflow: hidden;
box-shadow: inset 0 0 5px rgba(0,0,0,0.3);
}

#progress-bar {
height: 100%;
width: 0%;
background-color: #ffcc00;
border-radius: 10px 0 0 10px;
transition: width 0.4s ease;
}

#board {
width: 400px;
height: 400px;
Expand Down