1.3.1 • Published 4 months ago
mystery-box v1.3.1
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
Option | Type | Default | Description |
---|---|---|---|
showResultDelay | number | 1000 | Delay before showing results (in ms). |
roundResetDelay | number | 1000 | Delay before resetting round (in ms). |
roundsTotal | number | 2 | Total number of rounds. |
onRoundStart | function | null | Callback function triggered at the start of each round. |
onRoundEnd | function | null | Callback function triggered at the end of each round. |
onGameEnd | function | null | Callback function triggered when all rounds are completed. |
➤ Methods
Method | Parameters | Returns | Description |
---|---|---|---|
init() | - | void | Initializes 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.
- The clicked item gets
- 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