Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. {
  2. init: function(elevators, floors) {
  3.  
  4. var requestedFloors = [];
  5.  
  6. for (var i = 0; i < floors.length; i++) {
  7. (function (i) {
  8. var floor = floors[i];
  9. floor.on('up_button_pressed', function () {
  10. if (i % 2) {
  11. elevators[0].goToFloor(i);
  12. } else {
  13. elevators[1].goToFloor(i);
  14. }
  15. });
  16. floor.on('down_button_pressed', function () {
  17. if (i % 2) {
  18. elevators[0].goToFloor(i);
  19. } else {
  20. elevators[1].goToFloor(i);
  21. }
  22. });
  23. })(i);
  24. };
  25.  
  26. for (var i = 0; i < elevators.length; i++) {
  27. (function (i) {
  28. var elevator = elevators[i];
  29.  
  30. elevator.on('idle', function() {
  31. elevator.goToFloor(0);
  32. });
  33. elevator.on('floor_button_pressed', function (floorNum) {
  34. elevator.goToFloor(floorNum);
  35. });
  36. elevator.on('stopped_at_floor', function (floorNum) {
  37. // if (floorNum == (1)) {
  38. // elevator.goToFloor(0, true);
  39. // };
  40. });
  41. elevator.on('passing_floor', function (floorNum, direction) {
  42. console.log(floorNum, direction);
  43. });
  44. })(i);
  45. };
  46. },
  47.  
  48. update: function(dt, elevators, floors) {
  49. // We normally don't need to do anything here
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement