Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- roman_elevator.js
- var DIRECTION_DOWN = -1
- var DIRECTION_NONE = 0
- var DIRECTION_UP = 1
- function HardwareElevator(){};
- HardwareElevator.prototype = {
- moveUp:function(){console.log('moving up');},
- moveDown:function(){console.log('moving down');},
- stopAndOpenDoors:function(){console.log('stopping and opening doors');},
- getCurrentFloor:function(){console.log('getting current floor');},
- getCurrentDirection:function(){console.log('getting current drection');}
- }
- function Elevator() {
- this.hw = new HardwareElevator();
- this.hw.addEventListener("doorsClosed", _.bind(this.onDoorsClosed, this));
- this.hw.addEventListener("beforeFloor", _.bind(this.onBeforeFloor, this));
- this.destinationFloor = 0;
- }
- Elevator.prototype = {
- onDoorsClosed: function(floor) {
- if (this.destinationFloor > floor) {
- this.hw.moveUp();
- } else if (this.destinationFloor < floor) {
- this.hw.moveDown();
- }
- },
- onBeforeFloor: function(floor, direction) {
- if (this.destinationFloor === floor) {
- this.hw.stopAndOpenDoors();
- }
- },
- floorButtonPressed: function(floor, direction) {
- if (this.hw.getCurrentDirection === DIRECTION_NONE) {
- this.destinationFloor = floor;
- if (this.hw.getCurrentFloor > floor) {
- this.hw.moveDown();
- } else if (this.hw.getCurrentFloor < floor) {
- this.hw.moveUp();
- } else {
- this.stopAndOpenDoors();
- }
- }
- },
- cabinButtonPressed: function(floor) {
- if (this.hw.getCurrentDirection === DIRECTION_NONE) {
- this.destinationFloor = floor;
- if (this.hw.getCurrentFloor > floor) {
- this.hw.moveDown();
- } else if (this.hw.getCurrentFloor < floor) {
- this.hw.moveUp();
- } else {
- this.hw.stopAndOpenDoors();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement