-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (61 loc) · 1.67 KB
/
index.js
File metadata and controls
69 lines (61 loc) · 1.67 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
import { Parking } from "./parking.js";
import readline from "readline";
let parking = new Parking();
let prompt =
"Please choose an option [ p - Park a vehicle, u - Unpark a vehicle, m - Show map, h - Show history, x - exit ]:";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt,
});
rl.prompt();
rl.on("line", (line) => {
switch (line.trim()) {
case "x":
rl.close();
break;
case "p":
rl.question("Vehicle size [ 0-S, 1-M, 2-L ]: ", function (size) {
rl.question(
"Choose entrance [ 0-North, 1-West, 2-East ]",
function (entrance) {
rl.question("Type in your plate number: ", function (plateNumber) {
parking.parkVehicle(size, entrance, plateNumber);
parking.showMap();
parking.showParkHistory();
rl.prompt();
});
}
);
});
break;
case "u":
rl.question(
"Location of vehicle to unpark. Seperate by a space [row column]: ",
function (loc) {
rl.question("Plate number: ", function (plateNumber) {
let strLoc = loc.trim().split(" ");
if (strLoc.length >= 2) {
let row = strLoc[0];
let col = strLoc[1];
parking.unparkVehicle(row, col, plateNumber);
console.log("Vehicle unparked!");
}
});
}
);
break;
case "m":
parking.showMap();
break;
case "h":
parking.showParkHistory();
break;
default:
break;
}
rl.prompt();
}).on("close", () => {
console.log("Goodbye!");
process.exit(0);
});