app/scripts/core/gameCoordinator.js
/**
   * Resets gameCoordinator values to their default states
   */
Resets gameCoordinator values to their default states
Resets gameCoordinator values to their default states
reset() {
    this.activeTimers = [];
    this.points = 0;
    this.level = 1;
    this.lives = 2;
    this.extraLifeGiven = false;
    this.remainingDots = 0;
    this.allowKeyPresses = true;
    this.allowPacmanMovement = false;
    this.allowPause = false;
    this.cutscene = true;
    if (this.firstGame) {
      setInterval(() => {
        this.collisionDetectionLoop();
      }, 500);
      this.pacman = new Pacman(
        this.scaledTileSize,
        this.mazeArray,
        new CharacterUtil(),
      );
      this.blinky = new Ghost(
        this.scaledTileSize,
        this.mazeArray,
        this.pacman,
        'blinky',
        this.level,
        new CharacterUtil(),
      );
      this.pinky = new Ghost(
        this.scaledTileSize,
        this.mazeArray,
        this.pacman,
        'pinky',
        this.level,
        new CharacterUtil(),
      );
      this.inky = new Ghost(
        this.scaledTileSize,
        this.mazeArray,
        this.pacman,
        'inky',
        this.level,
        new CharacterUtil(),
        this.blinky,
      );
      this.clyde = new Ghost(
        this.scaledTileSize,
        this.mazeArray,
        this.pacman,
        'clyde',
        this.level,
        new CharacterUtil(),
      );
      this.fruit = new Pickup(
        'fruit',
        this.scaledTileSize,
        13.5,
        17,
        this.pacman,
        this.mazeDiv,
        100,
      );
    }
    this.entityList = [
      this.pacman,
      this.blinky,
      this.pinky,
      this.inky,
      this.clyde,
      this.fruit,
    ];
    this.ghosts = [this.blinky, this.pinky, this.inky, this.clyde];
    this.scaredGhosts = [];
    this.eyeGhosts = 0;
    if (this.firstGame) {
      this.drawMaze(this.mazeArray, this.entityList);
      this.soundManager = new SoundManager();
      this.setUiDimensions();
    } else {
      this.pacman.reset();
      this.ghosts.forEach((ghost) => {
        ghost.reset(true);
      });
      this.pickups.forEach((pickup) => {
        if (pickup.type !== 'fruit') {
          this.remainingDots += 1;
          pickup.reset();
          this.entityList.push(pickup);
        }
      });
    }
    this.pointsDisplay.innerHTML = '00';
    this.highScoreDisplay.innerHTML = this.highScore || '00';
    this.clearDisplay(this.fruitDisplay);
    const volumePreference = parseInt(
      localStorage.getItem('volumePreference') || 1,
      10,
    );
    this.setSoundButtonIcon(volumePreference);
    this.soundManager.setMasterVolume(volumePreference);
  }
reset ( ) { this . activeTimers = [ ] ; this . points = 0 ; this . level = 1 ; this . lives = 2 ; this . extraLifeGiven = false ; this . remainingDots = 0 ; this . allowKeyPresses = true ; this . allowPacmanMovement = false ; this . allowPause = false ; this . cutscene = true ; if ( this . firstGame ) { setInterval ( ( ) => { this . collisionDetectionLoop ( ) ; } , 500 ) ; this . pacman = new Pacman ( this . scaledTileSize , this . mazeArray , new CharacterUtil ( ) , ) ; this . blinky = new Ghost ( this . scaledTileSize , this . mazeArray , this . pacman , 'blinky' , this . level , new CharacterUtil ( ) , ) ; this . pinky = new Ghost ( this . scaledTileSize , this . mazeArray , this . pacman , 'pinky' , this . level , new CharacterUtil ( ) , ) ; this . inky = new Ghost ( this . scaledTileSize , this . mazeArray , this . pacman , 'inky' , this . level , new CharacterUtil ( ) , this . blinky , ) ; this . clyde = new Ghost ( this . scaledTileSize , this . mazeArray , this . pacman , 'clyde' , this . level , new CharacterUtil ( ) , ) ; this . fruit = new Pickup ( 'fruit' , this . scaledTileSize , 13.5 , 17 , this . pacman , this . mazeDiv , 100 , ) ; } this . entityList = [ this . pacman , this . blinky , this . pinky , this . inky , this . clyde , this . fruit , ] ; this . ghosts = [ this . blinky , this . pinky , this . inky , this . clyde ] ; this . scaredGhosts = [ ] ; this . eyeGhosts = 0 ; if ( this . firstGame ) { this . drawMaze ( this . mazeArray , this . entityList ) ; this . soundManager = new SoundManager ( ) ; this . setUiDimensions ( ) ; } else { this . pacman . reset ( ) ; this . ghosts . forEach ( ( ghost ) => { ghost . reset ( true ) ; } ) ; this . pickups . forEach ( ( pickup ) => { if ( pickup . type !== 'fruit' ) { this . remainingDots += 1 ; pickup . reset ( ) ; this . entityList . push ( pickup ) ; } } ) ; } this . pointsDisplay . innerHTML = '00' ; this . highScoreDisplay . innerHTML = this . highScore || '00' ; this . clearDisplay ( this . fruitDisplay ) ; const volumePreference = parseInt ( localStorage . getItem ( 'volumePreference' ) || 1 , 10 , ) ; this . setSoundButtonIcon ( volumePreference ) ; this . soundManager . setMasterVolume ( volumePreference ) ; }
Resets gameCoordinator values to their default states
Resets gameCoordinator values to their default states
// this.highScore = localStorage.getItem('highScore');