From f03997c4a477da94e572c26da59c22e791b2ce81 Mon Sep 17 00:00:00 2001 From: "Saw, Hansly Kendrich" Date: Thu, 15 Sep 2022 18:16:09 +0800 Subject: [PATCH] added reward checking --- index.html | 18 +++++++++--------- scripts/app.js | 14 ++++++++++++++ scripts/iRoll.js | 28 ++++++++++++++++++++++------ scripts/interface.js | 9 ++++++++- scripts/offline.js | 35 +++++++++++++++++++++++++++++++++++ styles/dice.css | 4 ++-- 6 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 scripts/app.js create mode 100644 scripts/offline.js diff --git a/index.html b/index.html index a7c9335..1efefb5 100644 --- a/index.html +++ b/index.html @@ -1,11 +1,17 @@ + + RollDice + + + + @@ -17,15 +23,15 @@
  • RollDice
  • - +
    @@ -65,12 +71,6 @@ -
    -
    -
    -

    -
    -
    diff --git a/scripts/app.js b/scripts/app.js new file mode 100644 index 0000000..63b3b7c --- /dev/null +++ b/scripts/app.js @@ -0,0 +1,14 @@ +/* app.js +service workers +*/ + +var app = { + "name": "RollDice", + "description": "Chinese Dice Game", + "authors": ['buzz-lightsnack-2007'], + "sourcecode": "https://gitdab.com/buzz-lightsnack-2007/RollDice" +} + +if('serviceWorker' in navigator) { + navigator.serviceWorker.register('scripts/offline.js', { scope: '/' }); +} diff --git a/scripts/iRoll.js b/scripts/iRoll.js index d4b80e1..4a066a5 100644 --- a/scripts/iRoll.js +++ b/scripts/iRoll.js @@ -7,6 +7,7 @@ function RollOnInterface(muteSound = false, animation = true, times = 1) { if (animation) { + if (muteSound == false) {soundEffects.hit.play();}; app_dice_appearanceToggle(false); }; @@ -19,8 +20,6 @@ function RollOnInterface(muteSound = false, animation = true, times = 1) { function playSound() { if (roll.result) { soundEffects.ding.play() - } else { - soundEffects.fallout.play() }; }; @@ -43,7 +42,7 @@ function RollOnInterface(muteSound = false, animation = true, times = 1) { $(dice_identifier).addClass(dice_className); if ((value_dices_current == 4) || (value_dices_current == 1)) { - $(dice_identifier).addClass('orange-text'); + $(dice_identifier).addClass('red-text text-accent-1'); } else { $(dice_identifier).addClass('white-text'); } @@ -51,6 +50,25 @@ function RollOnInterface(muteSound = false, animation = true, times = 1) { }; + function showReward() { + let results = roll.result; + + switch (results) { + case 1: M.toast({text: '', html: '

    Six fours!

    '}); break; + case 1.1: M.toast({text: '', html: '

    Six ones!

    '}); break; + case 1.2: M.toast({text: '', html: '

    Six of a kind!

    '}); break; + case 1.3: M.toast({text: '', html: '

    Five fours!

    '}); break; + case 1.4: M.toast({text: '', html: '

    Five of a kind!

    '}); break; + case 1.5: M.toast({text: '', html: '

    Four fours!

    '}); break; + case 2: M.toast({text: '', html: '

    Straight!

    '}); break; + case 2.1: M.toast({text: '', html: '

    Three of a kind!

    '}); break; + case 3: M.toast({text: '', html: '

    Four of a kind!

    '}); break; + case 4: M.toast({text: '', html: '

    Three fours!

    '}); break; + case 5: M.toast({text: '', html: '

    Two fours!

    '}); break; + case 6: M.toast({text: '', html: '

    One four!

    '}); break; + } + }; + function rollEffect() { $('.btn-floating').removeClass('pulse'); @@ -61,10 +79,8 @@ function RollOnInterface(muteSound = false, animation = true, times = 1) { }; setTimeout(function() { - rollEffect(); + rollEffect(); showReward(); }, 750); - instance.next(); - return (roll); } diff --git a/scripts/interface.js b/scripts/interface.js index c947a1b..7d8d493 100644 --- a/scripts/interface.js +++ b/scripts/interface.js @@ -3,7 +3,7 @@ let soundEffects = { 'ding': new Audio('media/ding.mp4'), - 'fallout': new Audio('media/Shells_falls-Marcel-829263474.mp3'), + 'hit': new Audio('media/Shells_falls-Marcel-829263474.mp3'), 'tada': new Audio('media/tada.mp3') } @@ -14,3 +14,10 @@ function app_dice_appearanceToggle(setting = true) { $('.dice').addClass("scale-out"); } }; + +function app_about_appearanceToggle() { + let aboutMessage = (app.name.toUpperCase() + ': ' + app.description + '\n\n' + 'Maintained by ' + app.authors + '.\n' + 'Source code available at: ' + app.sourcecode); + + console.log(aboutMessage); + alert(aboutMessage); +} diff --git a/scripts/offline.js b/scripts/offline.js new file mode 100644 index 0000000..c170a29 --- /dev/null +++ b/scripts/offline.js @@ -0,0 +1,35 @@ +/* offline.js +Make app available offline */ + +const CACHE_NAME = `RollDice`; + +// Use the install event to pre-cache all initial resources. +self.addEventListener('install', event => { + event.waitUntil((async () => { + const cache = await caches.open(CACHE_NAME); + cache.addAll(['/']); + })()); +}); + +self.addEventListener('fetch', event => { + event.respondWith((async () => { + const cache = await caches.open(CACHE_NAME); + + try { + // Try to fetch the resource from the network. + const fetchResponse = await fetch(event.request); + + // Save the resource in the cache. + cache.put(event.request, fetchResponse.clone()); + + // And return it. + return fetchResponse; + } catch (e) { + // Fetching didn't work get the resource from the cache. + const cachedResponse = await cache.match(event.request); + + // And return it. + return cachedResponse; + } + })()); +}); diff --git a/styles/dice.css b/styles/dice.css index 8b20909..9e7ae2d 100644 --- a/styles/dice.css +++ b/styles/dice.css @@ -1,7 +1,7 @@ /* dice.css styles for the dice - */ + */ #dice-1, #dice-2, #dice-3, #dice-4, #dice-5, #dice-6 { - font-size: 750%; + font-size: 625%; }