Advertisement
goldnera

Mission Manager

Apr 30th, 2023
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class MissionManager {
  3.   constructor() {
  4.     this.currentMission = null;
  5.     this.missionList = [];
  6.   }
  7.  
  8.   addMission(mission) {
  9.     this.missionList.push(mission);
  10.   }
  11.  
  12.   startMission(missionName) {
  13.     const mission = this.missionList.find((mission) => mission.name === missionName);
  14.     if (!mission) {
  15.       console.log(`Mission "${missionName}" not found!`);
  16.       return;
  17.     }
  18.     this.currentMission = mission;
  19.     console.log(`Starting mission "${mission.name}"...`);
  20.    
  21.   }
  22.  
  23.   completeMission() {
  24.     if (!this.currentMission) {
  25.       console.log(`No mission currently in progress!`);
  26.       return;
  27.     }
  28.     console.log(`Completing mission "${this.currentMission.name}"...`);
  29.     # Complete mission logic here...
  30.     this.currentMission = null;
  31.   }
  32. }
  33.  
  34.  
  35. const missionManager = new MissionManager();
  36.  
  37.  
  38. missionManager.addMission({ name: 'Collect 10 Gems' });
  39. missionManager.addMission({ name: 'Defeat the Boss' });
  40.  
  41.  
  42. missionManager.startMission('Collect 10 Gems');
  43.  
  44.  
  45. missionManager.completeMission();
  46.  
  47.  
  48. missionManager.startMission('Defeat the Boss');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement