diff --git a/starter_code/.gitignore b/starter_code/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/starter_code/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/starter_code/elevator.js b/starter_code/elevator.js index 5339f35..0627811 100644 --- a/starter_code/elevator.js +++ b/starter_code/elevator.js @@ -1,19 +1,57 @@ class Elevator { - constructor(){ - this.floor = 0; - this.MAXFLOOR = 10; - this.requests = []; + constructor() { + this.floor = 0; + this.MAXFLOOR = 10; + this.requests = []; + this.direction = "up"; + this.interval; } - start() { } - stop() { } - update() { } - _passengersEnter() { } - _passengersLeave() { } - floorUp() { } - floorDown() { } - call() { } - log() { } + start() { + //comprueba con el comprueba el floor y si esta en maxfloor no aumenta mas y baja + this.interval = setInterval(() => { + /* if (this.floor < this.MAXFLOOR && this.direction == "up") { + + this.floorUp() + } else if(this.floor >= 0 && this.direction == "down") { + this.floorDown() + + } */ + this.floorUp(); + this.update(); + }, 1000); + } + +stop() {} +update() { + return this.log(); +} +_passengersEnter() {} +_passengersLeave() {} +floorUp() { + if (this.floor < this.MAXFLOOR && this.direction === 'up') { + this.floor++; + } else { + this.direction = 'down'; + this.floorDown(); + + } +} +floorDown() { + if (this.floor > 0 && this.direction == 'down') { + this.floor--; + } else { + this.direction = "up"; + this.floorUp(); + } + +} +call() {} +log() { + console.log(`Direction: ${this.direction} / Floor: ${this.floor}`); + + +} } -module.exports = Elevator; +module.exports = Elevator; \ No newline at end of file diff --git a/starter_code/index.js b/starter_code/index.js index 5e480eb..f0531af 100644 --- a/starter_code/index.js +++ b/starter_code/index.js @@ -1 +1,3 @@ const Elevator = require('./elevator.js'); + const elevator1= new Elevator(); +elevator1.start(); \ No newline at end of file