From 9e8d4544c50e32428e384eb525a6d8bedf619016 Mon Sep 17 00:00:00 2001 From: Muaath Alqarni Date: Fri, 12 Apr 2024 01:47:01 +0300 Subject: [PATCH] Init --- README.md | 7 +++ check.html | 13 +++++ css/game.css | 34 +++++++++++++ css/style.css | 15 ++++++ game.html | 47 ++++++++++++++++++ index.html | 16 +++++++ js/algo.js | 1 + js/config.js | 1 + js/game.js | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 263 insertions(+) create mode 100644 README.md create mode 100644 check.html create mode 100644 css/game.css create mode 100644 css/style.css create mode 100644 game.html create mode 100644 index.html create mode 100644 js/algo.js create mode 100644 js/config.js create mode 100644 js/game.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..02475b0 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Falling Sambosas + +This game was created after Falling Sambosas problem in [MRB3 Ramadan Contest 1445](https) orignally by [emad234](https://codeforces.com/emad234). + +## Algorithm + +This problem has two different algorithms, the one used here in the game was the fastest \ No newline at end of file diff --git a/check.html b/check.html new file mode 100644 index 0000000..0592cfe --- /dev/null +++ b/check.html @@ -0,0 +1,13 @@ + + + + Falling Sambosas - Check + + + + + +

Coming soon..

+
or not coming
+ + \ No newline at end of file diff --git a/css/game.css b/css/game.css new file mode 100644 index 0000000..15a412b --- /dev/null +++ b/css/game.css @@ -0,0 +1,34 @@ +div { + min-width: 200px; + min-height: 20px; +} +#sky { + background-color: aqua; + height: 620px; + width: 100%; +} +#ground { + width: 100%; + background-color: chocolate; +} +* { + box-sizing: border-box; + margin: 0px; +} +svg { + position: absolute; + width: 20px; + height: 20px; +} + +.sambosa { + fill: burlywood; + stroke: brown; + stroke-width: 1px; +} + +.emad { + fill: blue; + stroke: brown; + stroke-width: 1px; +} \ No newline at end of file diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..54824d0 --- /dev/null +++ b/css/style.css @@ -0,0 +1,15 @@ +.button { + text-decoration: none; + color: white; + background-color: rgb(79, 161, 219); + padding: 10px; + margin: 10px; +} + +.button:hover { + background-color: rgb(91, 181, 246); +} + +.center { + text-align: center; +} \ No newline at end of file diff --git a/game.html b/game.html new file mode 100644 index 0000000..9b27bba --- /dev/null +++ b/game.html @@ -0,0 +1,47 @@ + + + + Falling Sambosas + + + + + +
+
+

Score:

+

Time:

+
+ + + +
+
+
+
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +
+ +
+ + + +
+
+ + + +
+ + + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..f280475 --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + Falling Sambosas - Overview + + + + + + +

Falling Sambosas

+ Play the game + Test your code against a sample + Overview about the game + + \ No newline at end of file diff --git a/js/algo.js b/js/algo.js new file mode 100644 index 0000000..903ba38 --- /dev/null +++ b/js/algo.js @@ -0,0 +1 @@ +// TODO: Write algorithms that solves the problem here \ No newline at end of file diff --git a/js/config.js b/js/config.js new file mode 100644 index 0000000..d2e1352 --- /dev/null +++ b/js/config.js @@ -0,0 +1 @@ +const RefreshRate = 30; // millisecond \ No newline at end of file diff --git a/js/game.js b/js/game.js new file mode 100644 index 0000000..67de601 --- /dev/null +++ b/js/game.js @@ -0,0 +1,129 @@ +var N = 9; +var X = [1, 2, 3, 2, 4, 1, 4, 5, 2, 5]; +var Y = [4, 7, 3, 9, 5, 2, 8, 1, 4, 9]; +var PLAY = [1, 0, 1, 0, 0, 0, 0, 0, 0, 0]; // Either 0, 1, -1 + +// Constants +const DELAY = 750; +const MAX_X = 10; +const MAX_Y = 10; +const SPACE = 50; // px + +// Const DOM +const SampleBtn = document.querySelector('#sample'); +const RandomBtn = document.querySelector('#random'); +const ClearBtn = document.querySelector('#clear'); +const MovesInp = document.querySelector('#moves'); + +const Player = document.querySelector('#player'); +const SKY_BOX = document.querySelector('#sky'); + +var Level = 0; +var Position = 0; +var Sambosas = []; +var SambosasObj = []; +var Score = 0; + +function movePlayer(diff) { + Position += parseInt(diff); + Player.style.left = Position * SPACE + "px"; +} + +function setScore(sc) { + Score = sc; + ScoreLabel.textContent = Score; +} + +function clearSambosas() { + Position = 0; + Score = 0; + movePlayer(0); + setScore(0); + Level = 0; + TimeLabel.textContent = 0; + for (var i = 0; i < SambosasObj.length; i++) { + SambosasObj[i].remove(); + } + Sambosas = []; + SambosasObj = []; +} + +function processInput() { + clearSambosas(); + for (var i = 0; i < N; i++) { + Sambosas.push({x: X[i], y: Y[i]}); + } + MovesInp.value = "1, 0, 1, 0, 0, 0, 0, 0, 0, 0"; + initialize(); +} + +function randomInteger(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} +function randomInput() { + clearSambosas(); + for (var i = 0; i < N; i++) { + Sambosas.push({x: randomInteger(0, MAX_X), y: randomInteger(0, MAX_Y)}); + } + initialize(); +} + +function createSambosa(obj, id) { + var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + var sambosa = document.createElementNS("http://www.w3.org/2000/svg", "polygon"); + sambosa.classList.add("sambosa"); + sambosa.setAttribute("points", "0,20 20,20 10,0"); + svg.id = id + "xx"; + svg.style.left = obj.x * SPACE + "px"; + svg.style.top = (MAX_Y-obj.y+1) * SPACE + "px"; + svg.appendChild(sambosa); + return svg; +} + +function initialize() { + Level = 0; + Position = 0; + Score = 0; + for (var i = 0; i < N; i++) { + oop = createSambosa(Sambosas[i], i); + SKY_BOX.appendChild(oop); + console.log(oop); + SambosasObj.push(document.getElementById(i + "xx")); + } +} + +const ScoreLabel = document.querySelector("#score"); +const TimeLabel = document.querySelector("#time"); +function refresh() { + movePlayer(PLAY[Level]) + for (var i = 0; i < N; i++) { + if (Sambosas[i].y - Level == 1 && Sambosas[i].x == Position) + Score++; + if (Sambosas[i].y - Level == 0) + SambosasObj[i].style.display = "none"; + else + SambosasObj[i].style.top = ((MAX_Y-Sambosas[i].y+3) + Level) * SPACE + "px"; + } + setScore(Score); + + TimeLabel.textContent = Level; +} +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} +async function start() { + RandomBtn.disabled = "true"; + SampleBtn.disabled = "true"; + ClearBtn.disabled = "true"; + PLAY = MovesInp.value.split(","); + console.log(PLAY); + while (Level <= MAX_Y) { + console.log("Played " + Level); + refresh(); + Level++; + await sleep(DELAY); + } + RandomBtn.disabled = ""; + SampleBtn.disabled = ""; + ClearBtn.disabled = ""; +} \ No newline at end of file