From 3c2f43436031ac000b80ec2f868b4eb7e53676eb Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Thu, 17 Aug 2023 15:10:12 +0530 Subject: [PATCH 1/9] creating floor --- src/css/main.css | 200 ++++++++++++++++++++++++++++++++++++++++++++++ src/index.html | 31 +++++++ src/js/main.js | 112 ++++++++++++++++++++++++++ src/liftPage.html | 38 +++++++++ 4 files changed, 381 insertions(+) create mode 100644 src/liftPage.html diff --git a/src/css/main.css b/src/css/main.css index e69de29b..3309b81f 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -0,0 +1,200 @@ +* { + margin: 0; + padding: 0; +} +:root { + --font-primary: "Bebas Neue", cursive; + --font-secondary: "Inter", sans-serif; + --color-dark-800: #212529; + --color-gray-400: #dddddd; + --base-transition: 0.4s ease; + --radius-10: 10px; + --color-purple-600: #7c27ce; + --color-light-100: #fff; +} + + +.firstPage { + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + height: 100vh; + transition: var(--base-transition); +} +.page-heading { + font-family: var(--font-secondary); + font-size: 4rem; + letter-spacing: 2px; + text-align: center; + margin-bottom: 1rem; + color: var(--color-dark-800); +} + +.input_container { + display: flex; + flex-direction: column; + margin-bottom: 1rem; +} + +label, +input { + font-family: var(--font-secondary); +} + +label { + margin-left: 20%; +} + + +.lift-sim_input { + padding: 5px 10px; + font-size: 1rem; + border-radius: var(--radius-10); + margin-top: 5px; + min-width: 250px; + border: 2px solid var(--color-gray-400); + transition: var(--base-transition); +} + +.lift-sim_input:focus { + border-color: var(--color-dark-800); +} + +.createLiftFloorButton { + margin-top: 1rem; + padding: 5px 10px; + font-size: 1.5rem; + font-family: var(--font-secondary); + border: 2px solid var(--color-gray-400); + border-radius: var(--radius-10); + cursor: pointer; + transition: var(--base-transition); +} + +.social { + margin-top: 15px; +} +.social a { + margin: 0px 10px; + color: blue; +} + +.buttonLift { + display: flex; +} + +.button { + width: 50px; + display: flex; + flex-direction: column; + margin: 11px 18px; +} + +.button button { + margin: 2px; +} +.up { + font-size: 13px; + border-radius: 4px; + transition-duration: 0.4s; + background-color: white; + color: var(--color-dark-800); +} +.down { + font-size: 13px; + border-radius: 4px; + transition-duration: 0.4s; + background-color: white; + color: var(--color-dark-800); +} +.up:hover { + background-color: black; + color: white; +} +.down:hover { + background-color: black; + color: white; +} + +.mainLift { + display: flex; + /* margin-left: 20px; */ + padding-left: 2rem; +} +.lift { + width: 50px; + height: 60px; + background-color: var(--color-gray-400); + border: 2px solid black; + margin-right: 5px; + transition-property: transform; + transition-timing-function: ease-in; +} + +.gates { + display: flex; +} +.gate1, +.gate2 { + width: 25px; + height: 60px; + margin: 1px; + background-color: var(--color-dark-800); + transition: width 2.5s ease-in-out; +} +.gate1-move { + transform: translateX(-100%); +} + +.gate2-move { + transform: translateX(100%); +} + +/* second page ko none krh de rha hai */ +.secondPage { + display: none; + margin: 4% auto; +} +.hrfloorName { + display: flex; + flex-direction: row; + margin: 3px; +} +hr { + flex-grow: 1; + height: 1px; + border-top: 2px solid black; +} + +h2 { + width: 100%; + text-align: center; + border-bottom: 1px solid #000; + line-height: 0.1em; + margin: 10px 0 20px; +} + +h2 span { + background: #fff; + padding: 0 10px; +} + +.goToFirstPage { + font-size: 18x; + margin: 5px 0 10px 3px; + background-color: var(--color-dark-800); + color: white; + width: 80px; + height: 30px; + cursor: pointer; +} + +@media (width>500px) { + .lift { + margin-right: 55px; + } + .mainLift { + margin-left: 50px; + } +} diff --git a/src/index.html b/src/index.html index e69de29b..3183651b 100644 --- a/src/index.html +++ b/src/index.html @@ -0,0 +1,31 @@ + + + + + + + + + Document + + + +
+

Lift Simulation

+
+ + +
+
+ + +
+ + +
+
+ +
+ + + \ No newline at end of file diff --git a/src/js/main.js b/src/js/main.js index e69de29b..88d42595 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -0,0 +1,112 @@ +let simulate = document.querySelector('.createLiftFloorButton'); + + + +simulate.addEventListener('click', function (e) { + e.preventDefault(); + const floorInputValue = document.getElementById('floorNumber').value; + const liftInputValue = document.getElementById('liftNumber').value; + console.log(floorInputValue, liftInputValue) + + if (floorInputValue == "" || liftInputValue == "") { + alert('please enter the value') + } + + if (floorInputValue == "0" || liftInputValue == "0") { + alert('please enter the value') + } + else { + document.querySelector('.firstPage').style.display = 'none'; + document.querySelector('.secondPage').style.display = 'block'; + makingFloor() + } +} +) + + +function makingFloor () { + + let floorInput = document.querySelector('#floorNumber').value + let liftInput = document.querySelector('#liftNumber').value + + let mainLift = document.createElement('div') + mainLift.className = 'mainLift' + + for (let j = 1; j <= liftInput; j++) { + mainLift.innerHTML += ` +
+
+
+
+
+
+ ` + } + + + + + + + for (let i = floorInput; i > 0; i--) { + + let floordiv = document.createElement('div'); + floordiv.className = 'box'; + + if (i == 1) { + floordiv.appendChild(mainLift); + } + let buttonLift = document.createElement('div'); + buttonLift.className = 'buttonLift'; + + let buttondiv1 = document.createElement('div'); + buttondiv1.className = 'button'; + + let button1 = document.createElement("button"); + let text1 = document.createTextNode("Up"); + button1.className = "up"; + button1.setAttribute('id', `up${i}`); + button1.appendChild(text1); + + let button2 = document.createElement("button"); + let text2 = document.createTextNode("Down"); + button2.className = "down"; + button2.setAttribute('id', `down${i}`); + button2.appendChild(text2); + + buttondiv1.appendChild(button1); + buttondiv1.appendChild(button2); + + buttonLift.appendChild(buttondiv1); + + floordiv.appendChild(buttonLift); + + let hrdiv = document.createElement('div'); + hrdiv.className = 'hrfloorName'; + + + let hr = document.createElement('hr'); + + let spanFloorNo = document.createElement('span'); + spanFloorNo.innerText = `Floor ${i}`; + + hrdiv.appendChild(hr); + + + hrdiv.appendChild(spanFloorNo); + + floordiv.appendChild(hrdiv); + + document.querySelector('.secondPage').appendChild(floordiv); + if (i == floorInput) { + button1.style.display = 'none'; + } + if (i == 1) { + button2.style.display = 'none' + } + } + + + +} + diff --git a/src/liftPage.html b/src/liftPage.html new file mode 100644 index 00000000..a275561f --- /dev/null +++ b/src/liftPage.html @@ -0,0 +1,38 @@ + + + + + + + + Document + + + + +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+ Floor 1 +
+
+ + + + + + \ No newline at end of file From 227222381b641bfda72b454295d3a5b12e44e308 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Fri, 18 Aug 2023 15:20:51 +0530 Subject: [PATCH 2/9] lift movement remaining --- src/css/main.css | 1 - src/js/main.js | 111 ++++++++++++++++++++++------------------------- 2 files changed, 51 insertions(+), 61 deletions(-) diff --git a/src/css/main.css b/src/css/main.css index 3309b81f..49a5647e 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -151,7 +151,6 @@ label { transform: translateX(100%); } -/* second page ko none krh de rha hai */ .secondPage { display: none; margin: 4% auto; diff --git a/src/js/main.js b/src/js/main.js index 88d42595..46acea94 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -2,7 +2,7 @@ let simulate = document.querySelector('.createLiftFloorButton'); -simulate.addEventListener('click', function (e) { +simulate.addEventListener('click', e => { e.preventDefault(); const floorInputValue = document.getElementById('floorNumber').value; const liftInputValue = document.getElementById('liftNumber').value; @@ -24,11 +24,33 @@ simulate.addEventListener('click', function (e) { ) -function makingFloor () { +function makingFloor() { let floorInput = document.querySelector('#floorNumber').value let liftInput = document.querySelector('#liftNumber').value + for (let i = floorInput; i > 0; i--) { + + let floordiv = document.createElement('div'); + floordiv.className = 'box'; + + floordiv.innerHTML = ` +
+
+ + +
+
+
+
+
+ Floor ${i} +
+ ` + + document.querySelector(".secondPage").appendChild(floordiv) + } + let mainLift = document.createElement('div') mainLift.className = 'mainLift' @@ -45,68 +67,37 @@ function makingFloor () { + let allFloors = document.querySelectorAll(".mainLift") + document.querySelectorAll("#liftSection")[floorInput - 1].appendChild(mainLift) + document.querySelector("#down1").style.display = "none" + document.querySelector(`#up${floorInput}`).style.display = "none" + const upButtons = document.querySelectorAll(".up") + const downButtons = document.querySelectorAll(".down") + const allLifts = document.querySelectorAll(".lift") + let currentFloor = new Array(allLifts.length).fill(1) - for (let i = floorInput; i > 0; i--) { - - let floordiv = document.createElement('div'); - floordiv.className = 'box'; - - if (i == 1) { - floordiv.appendChild(mainLift); - } - let buttonLift = document.createElement('div'); - buttonLift.className = 'buttonLift'; - - let buttondiv1 = document.createElement('div'); - buttondiv1.className = 'button'; - - let button1 = document.createElement("button"); - let text1 = document.createTextNode("Up"); - button1.className = "up"; - button1.setAttribute('id', `up${i}`); - button1.appendChild(text1); - - let button2 = document.createElement("button"); - let text2 = document.createTextNode("Down"); - button2.className = "down"; - button2.setAttribute('id', `down${i}`); - button2.appendChild(text2); - - buttondiv1.appendChild(button1); - buttondiv1.appendChild(button2); - - buttonLift.appendChild(buttondiv1); - - floordiv.appendChild(buttonLift); - - let hrdiv = document.createElement('div'); - hrdiv.className = 'hrfloorName'; - - - let hr = document.createElement('hr'); - - let spanFloorNo = document.createElement('span'); - spanFloorNo.innerText = `Floor ${i}`; - - hrdiv.appendChild(hr); - - - hrdiv.appendChild(spanFloorNo); - - floordiv.appendChild(hrdiv); - - document.querySelector('.secondPage').appendChild(floordiv); - if (i == floorInput) { - button1.style.display = 'none'; - } - if (i == 1) { - button2.style.display = 'none' - } - } - + console.log(allFloors) + upButtons.forEach((upbtn, i) => { + let floorValue = upButtons.length - i; + upbtn.addEventListener("click", (event) => { + event.preventDefault() + // console.log(allFloors[floorInput - currentFloor[0]]) + for (let j = 0; j < allLifts.length; j++) { + if (allLifts[j].getAttribute('flag') == "free") { + moveLift(allLifts[j], allFloors[floorInput - currentFloor[j]], allFloors[floorInput - floorValue],) + break + } + } + }) + }) } + +function moveLift(lift, currentFloor, destinationFloor) { + // currentFloor.removeChild(lift); +console.log(lift, currentFloor, destinationFloor) +} \ No newline at end of file From 12101997177ee1459dd5dd3511eb835a1d55cca4 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sat, 19 Aug 2023 01:14:55 +0530 Subject: [PATCH 3/9] lift animation remaining --- src/js/main.js | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 46acea94..d47b6cdb 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -40,7 +40,7 @@ function makingFloor() {
-
+

@@ -51,12 +51,12 @@ function makingFloor() { document.querySelector(".secondPage").appendChild(floordiv) } - let mainLift = document.createElement('div') - mainLift.className = 'mainLift' + let mainLift = document.querySelectorAll('.mainLift') for (let j = 1; j <= liftInput; j++) { - mainLift.innerHTML += ` + mainLift[floorInput - 1].innerHTML += `
+

${j}

@@ -68,7 +68,6 @@ function makingFloor() { let allFloors = document.querySelectorAll(".mainLift") - document.querySelectorAll("#liftSection")[floorInput - 1].appendChild(mainLift) document.querySelector("#down1").style.display = "none" document.querySelector(`#up${floorInput}`).style.display = "none" @@ -78,7 +77,7 @@ function makingFloor() { let currentFloor = new Array(allLifts.length).fill(1) - console.log(allFloors) + upButtons.forEach((upbtn, i) => { let floorValue = upButtons.length - i; @@ -86,18 +85,51 @@ function makingFloor() { event.preventDefault() // console.log(allFloors[floorInput - currentFloor[0]]) for (let j = 0; j < allLifts.length; j++) { + if (allLifts[j].getAttribute('flag') == "free" & distanceCalculator(currentFloor, floorValue) == j) { + allLifts[j].setAttribute('flag', "busy") + moveLift(allLifts[j], allFloors[floorInput - currentFloor[j]], allFloors[floorInput - floorValue],) + currentFloor[j] = floorValue + console.log(currentFloor) + break + } + } + }) + }) + + downButtons.forEach((downbtn, i) => { + let floorValue = downButtons.length - i; + downbtn.addEventListener("click", (event) => { + event.preventDefault() + // console.log(allFloors[floorInput - currentFloor[0]]) + for (let j = 0; j < allLifts.length; j++ & distanceCalculator(currentFloor, floorValue) == j) { if (allLifts[j].getAttribute('flag') == "free") { + allLifts[j].setAttribute('flag', "busy") moveLift(allLifts[j], allFloors[floorInput - currentFloor[j]], allFloors[floorInput - floorValue],) + currentFloor[j] = floorValue break } + } }) }) } - +function distanceCalculator(liftsPositionArray, destinationFloor) { + let liftDisatnce = [...liftsPositionArray].map((position) => { + return Math.abs(position - destinationFloor) + }) + return liftDisatnce.indexOf(Math.min(...liftDisatnce)) +} function moveLift(lift, currentFloor, destinationFloor) { - // currentFloor.removeChild(lift); -console.log(lift, currentFloor, destinationFloor) + setTimeout(() => { + currentFloor.removeChild(lift); + setTimeout(() => { + destinationFloor.appendChild(lift) + lift.setAttribute('flag', "free") + + }, 2000) + + }, 2000); + console.log(lift, currentFloor, destinationFloor) } \ No newline at end of file From 13f24f48b864f0742edd87a130ccafc5c3b26c98 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sat, 19 Aug 2023 16:55:04 +0530 Subject: [PATCH 4/9] lift selection logic done animation remaing --- src/js/main.js | 59 ++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index d47b6cdb..aea7d608 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -83,53 +83,60 @@ function makingFloor() { let floorValue = upButtons.length - i; upbtn.addEventListener("click", (event) => { event.preventDefault() - // console.log(allFloors[floorInput - currentFloor[0]]) - for (let j = 0; j < allLifts.length; j++) { - if (allLifts[j].getAttribute('flag') == "free" & distanceCalculator(currentFloor, floorValue) == j) { - allLifts[j].setAttribute('flag', "busy") - moveLift(allLifts[j], allFloors[floorInput - currentFloor[j]], allFloors[floorInput - floorValue],) - currentFloor[j] = floorValue - console.log(currentFloor) - break - } - } + console.log(distanceCalculator(currentFloor, floorValue)) + distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { + if (allLifts[liftNo].getAttribute('flag') == "free") { + allLifts[liftNo].setAttribute('flag', "busy") + moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + currentFloor[liftNo] = floorValue + console.log(allLifts[liftNo]) + return false + } else return true + }) }) }) downButtons.forEach((downbtn, i) => { let floorValue = downButtons.length - i; downbtn.addEventListener("click", (event) => { - event.preventDefault() - // console.log(allFloors[floorInput - currentFloor[0]]) - for (let j = 0; j < allLifts.length; j++ & distanceCalculator(currentFloor, floorValue) == j) { - if (allLifts[j].getAttribute('flag') == "free") { - allLifts[j].setAttribute('flag', "busy") - moveLift(allLifts[j], allFloors[floorInput - currentFloor[j]], allFloors[floorInput - floorValue],) - currentFloor[j] = floorValue - break - } - - } + console.log(distanceCalculator(currentFloor, floorValue)) + distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { + if (allLifts[liftNo].getAttribute('flag') == "free") { + allLifts[liftNo].setAttribute('flag', "busy") + moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + currentFloor[liftNo] = floorValue + console.log(allLifts[liftNo]) + return false + } else return true + }) }) }) } function distanceCalculator(liftsPositionArray, destinationFloor) { - let liftDisatnce = [...liftsPositionArray].map((position) => { - return Math.abs(position - destinationFloor) + let liftDisatnce = [...liftsPositionArray].map((position, i) => { + return { distance: Math.abs(position - destinationFloor), index: i } }) - return liftDisatnce.indexOf(Math.min(...liftDisatnce)) + return liftDisatnce.sort((a, b) => a.distance - b.distance).map((e) => e.index) + // .indexOf(Math.min(...liftDisatnce)) } function moveLift(lift, currentFloor, destinationFloor) { + + // liftno.style.transform = `translateY(${-95 * (floorNo - 1)}px)`; + + // add styling transition-duration to particular lift i.e. we do this because Lift moving at 2s per floor + // let prev= `${2 * Math.abs(floorNo - oldFloorValue)}s` + // liftno.style.transitionDuration = prev; + setTimeout(() => { currentFloor.removeChild(lift); setTimeout(() => { destinationFloor.appendChild(lift) lift.setAttribute('flag', "free") - }, 2000) }, 2000); - console.log(lift, currentFloor, destinationFloor) + // console.log(lift, currentFloor, destinationFloor) + } \ No newline at end of file From d843ea136dcb96d3431dde113427bb0aee97277e Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sun, 20 Aug 2023 00:24:47 +0530 Subject: [PATCH 5/9] door animation remaing --- src/js/main.js | 36 ++++++++++++++++++++---------------- src/liftPage.html | 38 -------------------------------------- 2 files changed, 20 insertions(+), 54 deletions(-) delete mode 100644 src/liftPage.html diff --git a/src/js/main.js b/src/js/main.js index aea7d608..ff783326 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -56,7 +56,7 @@ function makingFloor() { for (let j = 1; j <= liftInput; j++) { mainLift[floorInput - 1].innerHTML += `
-

${j}

+
@@ -87,7 +87,9 @@ function makingFloor() { distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") - moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) + currentFloor[liftNo] = floorValue console.log(allLifts[liftNo]) return false @@ -103,7 +105,8 @@ function makingFloor() { distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") - moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) + moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) currentFloor[liftNo] = floorValue console.log(allLifts[liftNo]) return false @@ -118,25 +121,26 @@ function distanceCalculator(liftsPositionArray, destinationFloor) { return { distance: Math.abs(position - destinationFloor), index: i } }) return liftDisatnce.sort((a, b) => a.distance - b.distance).map((e) => e.index) - // .indexOf(Math.min(...liftDisatnce)) + } -function moveLift(lift, currentFloor, destinationFloor) { +function moveLift(lift, destinationFloor, currentFloor) { - // liftno.style.transform = `translateY(${-95 * (floorNo - 1)}px)`; + lift.style.transform = `translateY(${-95 * (destinationFloor - 1)}px)`; - // add styling transition-duration to particular lift i.e. we do this because Lift moving at 2s per floor - // let prev= `${2 * Math.abs(floorNo - oldFloorValue)}s` - // liftno.style.transitionDuration = prev; + + let prev = `${2 * Math.abs(destinationFloor - currentFloor)}s` + lift.style.transitionDuration = prev; setTimeout(() => { - currentFloor.removeChild(lift); - setTimeout(() => { - destinationFloor.appendChild(lift) - lift.setAttribute('flag', "free") - }, 2000) + // currentFloor.removeChild(lift); + // setTimeout(() => { + // destinationFloor.appendChild(lift) + lift.setAttribute('flag', "free") + }, 2000) - }, 2000); + // }, 2000); // console.log(lift, currentFloor, destinationFloor) -} \ No newline at end of file +} + diff --git a/src/liftPage.html b/src/liftPage.html deleted file mode 100644 index a275561f..00000000 --- a/src/liftPage.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - Document - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
- Floor 1 -
-
- - - - - - \ No newline at end of file From 666dbdccf308b5ec0d856bf7c828a96f6933d1a0 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sun, 20 Aug 2023 20:32:20 +0530 Subject: [PATCH 6/9] Done --- src/css/main.css | 7 ------- src/js/main.js | 37 +++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/css/main.css b/src/css/main.css index 49a5647e..e5f041d1 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -72,13 +72,6 @@ label { transition: var(--base-transition); } -.social { - margin-top: 15px; -} -.social a { - margin: 0px 10px; - color: blue; -} .buttonLift { display: flex; diff --git a/src/js/main.js b/src/js/main.js index ff783326..17572232 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -56,7 +56,6 @@ function makingFloor() { for (let j = 1; j <= liftInput; j++) { mainLift[floorInput - 1].innerHTML += `
-
@@ -83,15 +82,12 @@ function makingFloor() { let floorValue = upButtons.length - i; upbtn.addEventListener("click", (event) => { event.preventDefault() - console.log(distanceCalculator(currentFloor, floorValue)) distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) - currentFloor[liftNo] = floorValue - console.log(allLifts[liftNo]) return false } else return true }) @@ -101,14 +97,12 @@ function makingFloor() { downButtons.forEach((downbtn, i) => { let floorValue = downButtons.length - i; downbtn.addEventListener("click", (event) => { - console.log(distanceCalculator(currentFloor, floorValue)) distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) currentFloor[liftNo] = floorValue - console.log(allLifts[liftNo]) return false } else return true }) @@ -121,26 +115,33 @@ function distanceCalculator(liftsPositionArray, destinationFloor) { return { distance: Math.abs(position - destinationFloor), index: i } }) return liftDisatnce.sort((a, b) => a.distance - b.distance).map((e) => e.index) - } function moveLift(lift, destinationFloor, currentFloor) { - lift.style.transform = `translateY(${-95 * (destinationFloor - 1)}px)`; - - let prev = `${2 * Math.abs(destinationFloor - currentFloor)}s` lift.style.transitionDuration = prev; setTimeout(() => { - // currentFloor.removeChild(lift); - // setTimeout(() => { - // destinationFloor.appendChild(lift) - lift.setAttribute('flag', "free") - }, 2000) + openCloseGates(lift); + setTimeout(() => { + lift.setAttribute('flag', 'free') + }, 5500); + console.log(lift.getAttribute('flag')) + }, 2 * Math.abs(destinationFloor - currentFloor) * 1000) +} - // }, 2000); - // console.log(lift, currentFloor, destinationFloor) +function openCloseGates(lift) { + let gates = lift.children[0].children + console.log(gates[0]) + setTimeout(() => { + gates[0].style.width = '3px'; + gates[1].style.width = '3px'; + }, 1000) -} + setTimeout(() => { + gates[0].style.width = '25px'; + gates[1].style.width = '25px'; + }, 3500) +} \ No newline at end of file From f9a15a9ec17e26c69c24d4bf54ea5c1a33ace281 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sun, 20 Aug 2023 20:43:21 +0530 Subject: [PATCH 7/9] Done --- src/js/main.js | 56 +++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 17572232..1340caa2 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,4 +1,4 @@ -let simulate = document.querySelector('.createLiftFloorButton'); +const simulate = document.querySelector('.createLiftFloorButton'); @@ -6,7 +6,6 @@ simulate.addEventListener('click', e => { e.preventDefault(); const floorInputValue = document.getElementById('floorNumber').value; const liftInputValue = document.getElementById('liftNumber').value; - console.log(floorInputValue, liftInputValue) if (floorInputValue == "" || liftInputValue == "") { alert('please enter the value') @@ -24,14 +23,14 @@ simulate.addEventListener('click', e => { ) -function makingFloor() { +const makingFloor = () => { - let floorInput = document.querySelector('#floorNumber').value - let liftInput = document.querySelector('#liftNumber').value + const floorInput = document.querySelector('#floorNumber').value + const liftInput = document.querySelector('#liftNumber').value for (let i = floorInput; i > 0; i--) { - let floordiv = document.createElement('div'); + const floordiv = document.createElement('div'); floordiv.className = 'box'; floordiv.innerHTML = ` @@ -51,7 +50,7 @@ function makingFloor() { document.querySelector(".secondPage").appendChild(floordiv) } - let mainLift = document.querySelectorAll('.mainLift') + const mainLift = document.querySelectorAll('.mainLift') for (let j = 1; j <= liftInput; j++) { mainLift[floorInput - 1].innerHTML += ` @@ -66,7 +65,7 @@ function makingFloor() { - let allFloors = document.querySelectorAll(".mainLift") + const allFloors = document.querySelectorAll(".mainLift") document.querySelector("#down1").style.display = "none" document.querySelector(`#up${floorInput}`).style.display = "none" @@ -74,20 +73,20 @@ function makingFloor() { const downButtons = document.querySelectorAll(".down") const allLifts = document.querySelectorAll(".lift") - let currentFloor = new Array(allLifts.length).fill(1) + let liftCurrentFloor = new Array(allLifts.length).fill(1) upButtons.forEach((upbtn, i) => { - let floorValue = upButtons.length - i; + const floorValue = upButtons.length - i; upbtn.addEventListener("click", (event) => { event.preventDefault() - distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { + distanceCalculator(liftCurrentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") - // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) - moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) - currentFloor[liftNo] = floorValue + // moveLift(allLifts[liftNo], allFloors[floorInput - liftCurrentFloor[liftNo]], allFloors[floorInput - floorValue],) + moveLift(allLifts[liftNo], floorValue, liftCurrentFloor[liftNo]) + liftCurrentFloor[liftNo] = floorValue return false } else return true }) @@ -95,14 +94,14 @@ function makingFloor() { }) downButtons.forEach((downbtn, i) => { - let floorValue = downButtons.length - i; + const floorValue = downButtons.length - i; downbtn.addEventListener("click", (event) => { - distanceCalculator(currentFloor, floorValue).every((liftNo, i) => { + distanceCalculator(liftCurrentFloor, floorValue).every((liftNo, i) => { if (allLifts[liftNo].getAttribute('flag') == "free") { allLifts[liftNo].setAttribute('flag', "busy") - // moveLift(allLifts[liftNo], allFloors[floorInput - currentFloor[liftNo]], allFloors[floorInput - floorValue],) - moveLift(allLifts[liftNo], floorValue, currentFloor[liftNo]) - currentFloor[liftNo] = floorValue + // moveLift(allLifts[liftNo], allFloors[floorInput - liftCurrentFloor[liftNo]], allFloors[floorInput - floorValue],) + moveLift(allLifts[liftNo], floorValue, liftCurrentFloor[liftNo]) + liftCurrentFloor[liftNo] = floorValue return false } else return true }) @@ -110,30 +109,28 @@ function makingFloor() { }) } -function distanceCalculator(liftsPositionArray, destinationFloor) { - let liftDisatnce = [...liftsPositionArray].map((position, i) => { +distanceCalculator = (liftsPositionArray, destinationFloor) => { + const liftDisatnce = [...liftsPositionArray].map((position, i) => { return { distance: Math.abs(position - destinationFloor), index: i } }) return liftDisatnce.sort((a, b) => a.distance - b.distance).map((e) => e.index) } -function moveLift(lift, destinationFloor, currentFloor) { +const moveLift = (lift, destinationFloor, liftCurrentFloor) => { lift.style.transform = `translateY(${-95 * (destinationFloor - 1)}px)`; - let prev = `${2 * Math.abs(destinationFloor - currentFloor)}s` + const prev = `${2 * Math.abs(destinationFloor - liftCurrentFloor)}s` lift.style.transitionDuration = prev; setTimeout(() => { openCloseGates(lift); setTimeout(() => { lift.setAttribute('flag', 'free') - }, 5500); - console.log(lift.getAttribute('flag')) - }, 2 * Math.abs(destinationFloor - currentFloor) * 1000) + }, 4500); + }, 2 * Math.abs(destinationFloor - liftCurrentFloor) * 1000) } -function openCloseGates(lift) { - let gates = lift.children[0].children - console.log(gates[0]) +const openCloseGates = (lift) => { + const gates = lift.children[0].children setTimeout(() => { gates[0].style.width = '3px'; gates[1].style.width = '3px'; @@ -143,5 +140,4 @@ function openCloseGates(lift) { gates[0].style.width = '25px'; gates[1].style.width = '25px'; }, 3500) - } \ No newline at end of file From 69490466bae73dd3e88850106809584c1a127e42 Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Sun, 20 Aug 2023 20:48:57 +0530 Subject: [PATCH 8/9] Done --- netlify.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000..67560159 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,4 @@ +[[redirects]] +from = "/*" +to = "/index.html" +status = 200 \ No newline at end of file From bdf0dc09963de523f4add75797b74057a4c9cd0f Mon Sep 17 00:00:00 2001 From: Aasim Taif Date: Wed, 23 Aug 2023 12:21:36 +0530 Subject: [PATCH 9/9] Done --- netlify.toml | 4 ---- src/js/main.js | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 67560159..00000000 --- a/netlify.toml +++ /dev/null @@ -1,4 +0,0 @@ -[[redirects]] -from = "/*" -to = "/index.html" -status = 200 \ No newline at end of file diff --git a/src/js/main.js b/src/js/main.js index 1340caa2..7bf19fe6 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -140,4 +140,7 @@ const openCloseGates = (lift) => { gates[0].style.width = '25px'; gates[1].style.width = '25px'; }, 3500) -} \ No newline at end of file +} + + +//code by rahulsharmaah