Connexion
S'inscrire
Actualités
Quoi de neuf
Activités générales
Auteurs
Forums
Nouveaux messages
Rechercher un forum
Quoi de neuf
Nouveaux messages
Nouveaux messages de profil
Activités générales
Membres
Membres inscrits
Visiteurs actuels
Nouveaux messages de profil
Rechercher dans les messages des profils
Teams
Créé ton équipe
Quoi de neuf ?
Nouveaux messages
Rechercher un forum
Menu
Connexion
S'inscrire
Install the app
Install
Forums
Forums généraux
Informatique
Développement
Questions, aides et recherches
Besoin d'aide pour mon JS.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Vous utilisez un navigateur non à jour ou ancien. Il ne peut pas afficher ce site ou d'autres sites correctement.
Vous devez le mettre à jour ou utiliser un
navigateur alternatif
.
Répondre à la discussion
Message
<blockquote data-quote="Marshmello" data-source="post: 7368021" data-attributes="member: 187012"><p>Je cherche le moyen de déclarer mon elevator a la ligne 152...</p><p></p><p>[CODE]//SCENARIO #1</p><p></p><p></p><p>class Button {</p><p> constructor(direction, requestFloor) {</p><p> this.direction = direction;</p><p> this.requestFloor = requestFloor;</p><p> this.activateButton = false;</p><p> }</p><p>}</p><p></p><p>class insideButton {</p><p> constructor (FLOOR) {</p><p> this.FLOOR = FLOOR;</p><p> this.Status = "Desactivated";</p><p> }</p><p>}</p><p></p><p>class Elevator {</p><p> constructor(numberElevator, numberFloor) {</p><p> this.numberElevator = numberElevator;</p><p> this.direction = "NONE";</p><p> this.status = "idle";</p><p> this.floorList = [];</p><p> this.button_list = [];</p><p> for (var i = 0; i < numberFloor; i++) {</p><p> this.button_list.push(new insideButton(i));</p><p> }</p><p> this.currentFloor = 1;</p><p> }</p><p> move_next(){</p><p> let floorList = this.floorList</p><p> let numberFloor = floorList.shift();</p><p> if (this.currentFloor > numberFloor){</p><p> this.moveDown(numberFloor);</p><p> }</p><p> else if (this.currentFloor < numberFloor){</p><p> this.moveUp(numberFloor);</p><p> }</p><p> else {</p><p> this.openDoor();</p><p> }</p><p> }</p><p> moveDown(numberFloor) {</p><p> console.log ("Elevator GOING DOWN");</p><p> this.direction == 'down';</p><p> this.status == 'moving';</p><p> let interval = setInterval(() => {</p><p> this.currentFloor = this.currentFloor - 1</p><p> console.log(this.currentFloor)</p><p> if (this.currentFloor = numberFloor) {</p><p> clearInterval(interval)</p><p> console.log("ARRIVED AT THE FLOOR" + this.currentFloor)</p><p> this.openDoor()</p><p> }</p><p> }, 1000)</p><p> } </p><p> moveUp(numberFloor) {</p><p> console.log ("Elevator is going up");</p><p> this.direction == 'UP';</p><p> this.status == 'MOVING';</p><p> let interval = setInterval(() => {</p><p> this.currentFloor = this.currentFloor + 1</p><p> console.log(this.currentFloor)</p><p> if (this.currentFloor == numberFloor) {</p><p> clearInterval(interval)</p><p> console.log("Arrived at floor " + this.currentFloor)</p><p> this.openDoor()</p><p> }</p><p> }, 1000)</p><p> }</p><p> addFLOORtoList(numberFloor){</p><p> this.floorList.push(numberFloor);</p><p> if (this.direction = "UP"){</p><p> this.floorList.sort();</p><p> console.log(this.floorList)</p><p> }</p><p> else of (this.direction = "DOWN"); {</p><p> this.floorList.sort().reverse();</p><p> console.log(this.floorList)</p><p> }</p><p> }</p><p> </p><p> openDoor(){</p><p> console.log("OPEN DOOR AT THE FLOOR" + this.currentFloor)</p><p> this.status == 'openDoor';</p><p> setTimeout(() => {</p><p> this.closeDoor()</p><p> }, 5000);</p><p> }</p><p></p><p> closeDoor(){</p><p> console.log("DOOR CLOSED");</p><p> this.status = 'closeDoor';</p><p> if (this.floorList.length > 0) {</p><p> this.move_next()</p><p> }</p><p> }</p><p> activateinsideButton(numberElevator) {</p><p> console.log ("ACTIVATED BUTTON AT THE FLOOR" + numberFloor);</p><p> if (this.requestFloor = this.floorList) {</p><p> this.activateinsideButton = false;</p><p> }</p><p> if (this.requestFloor < this.floorList){</p><p> this.moveUp();</p><p> }</p><p> else if (this.requestFloor > this.floorList){</p><p> this.moveDown();</p><p> }</p><p> }</p><p>}</p><p></p><p>class Column {</p><p> constructor(numberFloor, numberElevator){ //</p><p> this.numberFloor = numberFloor;</p><p> this.numberElevator = numberElevator;</p><p> this.elevatorList =[];</p><p></p><p> for (let i = 0; i < this.numberElevator; i++) {</p><p> let elevator = new Elevator(i+1,numberFloor);</p><p> this.elevatorList.push(Elevator);</p><p> } </p><p> }</p><p>}</p><p></p><p>class ElevatorController {</p><p> constructor(numberFloor, nbElevatorPerColumn) {</p><p> this.numberFloor = numberFloor;</p><p> this.nbElevatorPerColumn = nbElevatorPerColumn;</p><p> this.Column = new Column(numberFloor, nbElevatorPerColumn);</p><p> this.button_list = [new Button()];</p><p> }</p><p></p><p> findElevator(numberFloor) {</p><p> var distanceFloor = 999;</p><p> var selectedElevator = null;</p><p> var findElevator = numberFloor;</p><p> for (var i = 0; i < this.Column.elevatorList.length; i++) {</p><p> var differenceFloor = Math.abs(numberFloor - this.Column.elevatorList [i].currentFloor);</p><p> if (differenceFloor < distanceFloor) {</p><p> distanceFloor = differenceFloor;</p><p> selectedElevator = this.Column.elevatorList[i];</p><p> }</p><p> return selectedElevator;</p><p> }</p><p> }</p><p></p><p> RequestElevator(numberFloor) {;</p><p> //var elevator = ; // What's it ! /</p><p> var findElevator = numberFloor; //</p><p> let elevator = findElevator;</p><p> this.elevator.activateinsideButton(numberFloor);</p><p> this.elevator.addFLOORtoList(numberFloor);</p><p> this.elevator.move_next();</p><p> }</p><p>}</p><p></p><p>const elevatorController = new ElevatorController(10, 2);</p><p>elevatorController.RequestElevator(7);[/CODE]</p><p></p><p></p><p>Merci a ceux qui pourront analyser le tout</p></blockquote><p></p>
[QUOTE="Marshmello, post: 7368021, member: 187012"] Je cherche le moyen de déclarer mon elevator a la ligne 152... [CODE]//SCENARIO #1 class Button { constructor(direction, requestFloor) { this.direction = direction; this.requestFloor = requestFloor; this.activateButton = false; } } class insideButton { constructor (FLOOR) { this.FLOOR = FLOOR; this.Status = "Desactivated"; } } class Elevator { constructor(numberElevator, numberFloor) { this.numberElevator = numberElevator; this.direction = "NONE"; this.status = "idle"; this.floorList = []; this.button_list = []; for (var i = 0; i < numberFloor; i++) { this.button_list.push(new insideButton(i)); } this.currentFloor = 1; } move_next(){ let floorList = this.floorList let numberFloor = floorList.shift(); if (this.currentFloor > numberFloor){ this.moveDown(numberFloor); } else if (this.currentFloor < numberFloor){ this.moveUp(numberFloor); } else { this.openDoor(); } } moveDown(numberFloor) { console.log ("Elevator GOING DOWN"); this.direction == 'down'; this.status == 'moving'; let interval = setInterval(() => { this.currentFloor = this.currentFloor - 1 console.log(this.currentFloor) if (this.currentFloor = numberFloor) { clearInterval(interval) console.log("ARRIVED AT THE FLOOR" + this.currentFloor) this.openDoor() } }, 1000) } moveUp(numberFloor) { console.log ("Elevator is going up"); this.direction == 'UP'; this.status == 'MOVING'; let interval = setInterval(() => { this.currentFloor = this.currentFloor + 1 console.log(this.currentFloor) if (this.currentFloor == numberFloor) { clearInterval(interval) console.log("Arrived at floor " + this.currentFloor) this.openDoor() } }, 1000) } addFLOORtoList(numberFloor){ this.floorList.push(numberFloor); if (this.direction = "UP"){ this.floorList.sort(); console.log(this.floorList) } else of (this.direction = "DOWN"); { this.floorList.sort().reverse(); console.log(this.floorList) } } openDoor(){ console.log("OPEN DOOR AT THE FLOOR" + this.currentFloor) this.status == 'openDoor'; setTimeout(() => { this.closeDoor() }, 5000); } closeDoor(){ console.log("DOOR CLOSED"); this.status = 'closeDoor'; if (this.floorList.length > 0) { this.move_next() } } activateinsideButton(numberElevator) { console.log ("ACTIVATED BUTTON AT THE FLOOR" + numberFloor); if (this.requestFloor = this.floorList) { this.activateinsideButton = false; } if (this.requestFloor < this.floorList){ this.moveUp(); } else if (this.requestFloor > this.floorList){ this.moveDown(); } } } class Column { constructor(numberFloor, numberElevator){ // this.numberFloor = numberFloor; this.numberElevator = numberElevator; this.elevatorList =[]; for (let i = 0; i < this.numberElevator; i++) { let elevator = new Elevator(i+1,numberFloor); this.elevatorList.push(Elevator); } } } class ElevatorController { constructor(numberFloor, nbElevatorPerColumn) { this.numberFloor = numberFloor; this.nbElevatorPerColumn = nbElevatorPerColumn; this.Column = new Column(numberFloor, nbElevatorPerColumn); this.button_list = [new Button()]; } findElevator(numberFloor) { var distanceFloor = 999; var selectedElevator = null; var findElevator = numberFloor; for (var i = 0; i < this.Column.elevatorList.length; i++) { var differenceFloor = Math.abs(numberFloor - this.Column.elevatorList [i].currentFloor); if (differenceFloor < distanceFloor) { distanceFloor = differenceFloor; selectedElevator = this.Column.elevatorList[i]; } return selectedElevator; } } RequestElevator(numberFloor) {; //var elevator = ; // What's it ! / var findElevator = numberFloor; // let elevator = findElevator; this.elevator.activateinsideButton(numberFloor); this.elevator.addFLOORtoList(numberFloor); this.elevator.move_next(); } } const elevatorController = new ElevatorController(10, 2); elevatorController.RequestElevator(7);[/CODE] Merci a ceux qui pourront analyser le tout [/QUOTE]
Insérer les citations…
Vérification
Publier la réponse
Forums
Forums généraux
Informatique
Développement
Questions, aides et recherches
Besoin d'aide pour mon JS.
Ce site utilise des cookies. En continuant à utiliser ce site, vous acceptez l'utilisation des cookies.
Acceptez
En savoir plus.…
Haut