How to set a limit for slot game reel spin autoplay?

by Philip Chow   Last Updated June 13, 2019 10:13 AM

I'm building a slot game, one line with three reel, using CocosCreator and Typescript.

There is an already built auto-spin function once start, it will spin the reel infinite times. The spin will only stop once user click the manual spin button.

I wish to set a default limit for the auto-play function in my slot game, so that once it reach the limit, the reel stop spinning. I tried to change some of the code before but unfortunately I not manage to make it. Below is the original code, I just selected the auto spin code from entire code base.

Does it need to add if statement?

Your help will be much appreciated.

/** using for auto spin */
//@property(CustomButton)
autoSpin:CustomButton = null;

rollingCounts:number = 0;

stopUpdate:boolean = true;

spincontroller:SpinController;

gameController:GameController;


public autoSpinCall() {

}

/**
 * start or stop spin
 */
public reelspins() {
  SoundManager.getInstance().stopSoundEffects();
  SoundManager.getInstance().playSoundEffect(SoundManager.SOUND.SPIN_START);
  this.gameController.spinCounterLabel.node.opacity = 0;
  this.gameController.stopWinnerTextAnim();

  this.isSpinStart = !this.isSpinStart;

  if (ConfigManager.getInstance().seletedGamePlugin.gameOnReelSpinStarted) {
    ConfigManager.getInstance().seletedGamePlugin.gameOnReelSpinStarted();
  }

  this.gameController.startSpin.disableButton();
  this.gameController.startSpin.showDollerIcon(false);
  this.schedule(this.reelCountUpdate,0.1);

  const updateSpin = (reel, index) => {
    reel.stopAnimationTime = 0.0;
    reel.stopAnimation();
    reel.node.stopAllActions();
    reel.currentSpinningState=reel.ReelSpinStateEnum.IDLE;
    const spinStartWithDelay = cc.callFunc(() => {
      if (reel.currentSpinningState==reel.ReelSpinStateEnum.IDLE) {
        reel.startSpin();
      }
    }, this);
    const duration = this.gameController.startSpin.isTurboPlayStart ? this.reelTurboEndAnimationDurations[index] : this.reelEndAnimationDurations[index];
    reel.node.runAction(cc.sequence(cc.delayTime(duration),spinStartWithDelay));
  };
  this.reels.forEach(updateSpin.bind(this));
  this.gameController.hideButtonsOnSpinClick();
}

      // if autospin -> spin the reels again
  this.unschedule(this.spinTheReelsAgain);
  this.scheduleOnce(this.spinTheReelsAgain ,(durations[this.reels.length - 1] + 0.2));
}

    /**
* Start spinning if Auto/Turbo play is enable
*/
public spinTheReelsAgain(dt) {
  this.gameController.startSpinningWithDelay(0.15);
}

public balanceCreditWin() {
  this.isWinAnimationStart=false;
  PlayerDataManager.getInstance().spinFinished();
}
public updateReelContainerLayout() {
  // const layout: cc.Layout = this.reelContainer.getComponent(cc.Layout);
  // layout.updateLayout();     
}



Related Questions


Updated August 24, 2019 04:13 AM

Updated July 18, 2019 10:13 AM

Updated August 14, 2015 17:05 PM

Updated April 01, 2017 21:13 PM

Updated January 04, 2019 09:13 AM