-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (88 loc) · 3.21 KB
/
Copy pathscript.js
File metadata and controls
104 lines (88 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const MAX_WEIGHT = 120; // Max weight per person
const MAX_PEOPLE = 10; // Max people in the lift
let currentWeight = 0;
let peopleInLift = 0;
let currentFloor = 0;
function addPerson() {
const weightInput = document.getElementById("personWeight").value;
const weight = parseInt(weightInput);
if (!weight || weight <= 0 || weight > MAX_WEIGHT) {
showAlert("Please enter a valid weight (1 - 120 kg).");
return;
}
if (peopleInLift < MAX_PEOPLE && currentWeight + weight <= MAX_WEIGHT * MAX_PEOPLE) {
currentWeight += weight;
peopleInLift++;
updateLiftStatus();
clearAlert();
enableExternalControls();
} else {
showAlert("Lift is full or overloaded!");
}
document.getElementById("personWeight").value = "";
}
function removePerson() {
const weightInput = document.getElementById("removeWeight").value;
const weightToRemove = parseInt(weightInput);
if (!weightToRemove || weightToRemove <= 0 || weightToRemove > MAX_WEIGHT) {
showAlert("Please enter a valid weight to remove (1 - 120 kg).");
return;
}
if (currentWeight - weightToRemove >= 0 && peopleInLift > 0) {
currentWeight -= weightToRemove;
peopleInLift--;
updateLiftStatus();
clearAlert();
enableExternalControls();
} else {
showAlert("Cannot remove this weight. Check the weight or people in the lift.");
}
document.getElementById("removeWeight").value = "";
}
function selectFloor(floor) {
if (peopleInLift > 0 && currentWeight <= MAX_WEIGHT * MAX_PEOPLE) {
clearAlert();
if (currentFloor !== floor) {
moveLift(floor);
currentFloor = floor;
disableExternalControls(); // Disable external controls when moving
}
} else {
showAlert("Cannot move. Lift is full or overloaded!");
}
}
function callElevator(floor) {
if (currentWeight <= MAX_WEIGHT * MAX_PEOPLE) {
clearAlert();
if (currentFloor !== floor) {
moveLift(floor);
currentFloor = floor;
disableExternalControls(); // Disable external controls when moving
}
} else {
showAlert("Cannot call elevator. Overloaded!");
}
}
function updateLiftStatus() {
document.getElementById("weight").innerText = currentWeight;
document.getElementById("people").innerText = peopleInLift;
}
function moveLift(floor) {
const lift = document.getElementById("lift");
const targetHeight = (floor - 1) * 80; // Adjust height for 5 floors
lift.style.height = targetHeight + "px";
}
function enableExternalControls() {
const externalButtons = document.querySelectorAll(".external-button");
externalButtons.forEach(button => button.disabled = false);
}
function disableExternalControls() {
const externalButtons = document.querySelectorAll(".external-button");
externalButtons.forEach(button => button.disabled = true);
}
function showAlert(message) {
document.getElementById("alert").innerText = message;
}
function clearAlert() {
document.getElementById("alert").innerText = "";
}