1.3.1 • Published 4 months ago

mystery-box v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

npm GitHub package version NPM Downloads

0.7kB gzipped

Demo

Install

$ yarn add mystery-box

Import

import MysteryBox from 'mystery-box';

Usage

const mysteryBox = new MysteryBox({
  showResultDelay: 1000,
  roundResetDelay: 1000,
  roundsTotal: 3,
  onRoundStart: (round) => console.log(`Round ${round} started`),
  onRoundEnd: (round) => {
    switch (round) {
      case 1:
        console.log(`Round ${round} complete`);
        break;
      case 2:
        console.log(`Round ${round} complete`);
        break;
      case 3:
        console.log(`Round ${round} complete`);
        break;
      ...
    }
  },
  onGameEnd: () => console.log(`Game finished`),
});

mysteryBox.init();

Options

OptionTypeDefaultDescription
showResultDelaynumber1000Delay before showing results (in ms).
roundResetDelaynumber1000Delay before resetting round (in ms).
roundsTotalnumber2Total number of rounds.
onRoundStartfunctionnullCallback function triggered at the start of each round.
onRoundEndfunctionnullCallback function triggered at the end of each round.
onGameEndfunctionnullCallback function triggered when all rounds are completed.

Methods

MethodParametersReturnsDescription
init()-voidInitializes the mystery box and attaches event listeners.

Behavior

  • The game consists of multiple rounds (roundsTotal), starting from 1 and with no upper limit.
  • Each round starts when the user clicks an item inside .mystery-box.
  • After a short delay (showResultDelay), the result of the round is revealed:
    • The clicked item gets box-won class.
    • The other items get box-loss class.
  • After another delay (roundResetDelay), the game resets for the next round.
  • When the last round finishes, the onGameEnd callback is triggered.

License

mystery-box is released under MIT license

1.3.1

4 months ago

1.3.1-dev.0

4 months ago

1.3.0

5 months ago

1.2.0

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago

0.0.1

5 months ago