diff --git a/starter_code/elevator.js b/starter_code/elevator.js index 5339f35..d2f0c52 100644 --- a/starter_code/elevator.js +++ b/starter_code/elevator.js @@ -3,17 +3,95 @@ class Elevator { this.floor = 0; this.MAXFLOOR = 10; this.requests = []; + this.interval = 0; + this.destinationFloor = 0; + + this.waitingList = []; + this.passengers = []; + this.requests = []; + } + + start() { + this.interval = setInterval( ()=> { + this.update() + },1000) + } + + stop() { + clearInterval(this.interval); + } + + update(x) { + this.log(); + this._passengersEnter(x) + + } + _passengersEnter(p) { + + for (let i = 0; i < this.waitingList.length; i++) + if (p.originFloor === this.floor) + { + passengers.push(this.waitingList[i]) + let temp = this.waitingList[i].name + this.requests.push(waitingList[i].destinationFloor) + console.log('Julia has enter the elevator') + + for (let j = 0; j < this.passengers.length; i++) + { + if (this.passengers[j].name === this.waitingList[i].name) + this.waitingList.splice(i,1) + } + } + console.log(this.requests,this.waitingList,this.passengers) } + _passengersLeave() { + for (let i = 0; i < this.passengers.length; i++) + if (this.passengers[i].destinationFloor === this.floor) + { + this.passengers[i].splice(i,1) + console.log('Julia has left the elevator') + } + + - start() { } - stop() { } - update() { } - _passengersEnter() { } - _passengersLeave() { } - floorUp() { } - floorDown() { } - call() { } - log() { } + } + floorUp() { + if (this.floor === this.MAXFLOOR) { + console.log('on est au MAX Chérie') + } + else this.floor += 1; + + } + floorDown() { + if (this.floor === 0 ) { + console.log('on va au sous sol chérie ?') + } + else this.floor -= 1; + } + + call(x) { + let movements = []; + movements.push(x); + //console.log(movements); + this.waitingList.push(x) + this.requests.push(x.originFloor) + + //console.log(this.requests) + } + + log() { + let data = { + floor: this.floor, + direction : 'up', + requests:[] + } + //console.log(data); + } } + + module.exports = Elevator; + + + diff --git a/starter_code/index.html b/starter_code/index.html new file mode 100644 index 0000000..e69de29 diff --git a/starter_code/index.js b/starter_code/index.js index 5e480eb..84c72a6 100644 --- a/starter_code/index.js +++ b/starter_code/index.js @@ -1 +1,13 @@ const Elevator = require('./elevator.js'); +const Person = require('./person.js'); + +var elevator = new Elevator(); +var person = new Person("Max", 2,0); +var person2 = new Person("Ju", 9,0); +var person3 = new Person("BOB", 3,5); +elevator.call(person); +elevator.call(person2); +elevator.log(); +elevator.update(person) +elevator.floorUp(person3) +elevator.update(person3) \ No newline at end of file diff --git a/starter_code/person.js b/starter_code/person.js index fddcc22..90f1dcc 100644 --- a/starter_code/person.js +++ b/starter_code/person.js @@ -1,5 +1,8 @@ class Person { constructor(name, originFloor, destinationFloor){ + this.name = name; + this.originFloor = originFloor; + this.destinationFloor = destinationFloor; } }