Created
August 2, 2024 07:25
-
-
Save saravanak/4f778729741fe15fdf904ae1140f29c9 to your computer and use it in GitHub Desktop.
Elevator Plugin Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const DIRS = { | |
| UP: 1, | |
| DOWN: 2, | |
| STOPPED: 0, | |
| }; | |
| class ElevatorLogic { | |
| currentFloor = 1; | |
| maxFloors = 1; | |
| currentDirection = DIRS.STOPPED; | |
| destinationFloor: number = -1; | |
| constructor(numFloors: number) { | |
| this.maxFloors = numFloors; | |
| } | |
| onFloorChanged() { | |
| if (this.currentFloor == this.destinationFloor) { | |
| this.currentDirection = DIRS.STOPPED; | |
| } | |
| } | |
| onFloorSelected(floor: number) { | |
| this.destinationFloor = floor; | |
| } | |
| onCalled(floor: number, direction: number) { | |
| this.destinationFloor = floor; | |
| console.log(direction); | |
| } | |
| onReady() { | |
| if (this.currentFloor < this.destinationFloor) { | |
| this.currentDirection = DIRS.UP; | |
| } else if (this.currentFloor > this.destinationFloor) { | |
| this.currentDirection = DIRS.DOWN; | |
| } | |
| } | |
| } | |
| export default ElevatorLogic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment