added reward checking
This commit is contained in:
		
							parent
							
								
									71665f6984
								
							
						
					
					
						commit
						f03997c4a4
					
				
					 6 changed files with 90 additions and 18 deletions
				
			
		
							
								
								
									
										14
									
								
								scripts/app.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								scripts/app.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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: '/' }); | ||||
| } | ||||
|  | @ -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: '<h4>Six fours!</h4>'}); break; | ||||
| 			case 1.1: M.toast({text: '',  html: '<h4>Six ones!</h4>'}); break; | ||||
| 			case 1.2: M.toast({text: '',  html: '<h4>Six of a kind!</h4>'}); break; | ||||
| 			case 1.3: M.toast({text: '',  html: '<h4>Five fours!</h4>'}); break; | ||||
| 			case 1.4: M.toast({text: '',  html: '<h4>Five of a kind!</h4>'}); break; | ||||
| 			case 1.5: M.toast({text: '',  html: '<h4>Four fours!</h4>'}); break; | ||||
| 			case 2: M.toast({text: '',  html: '<h4>Straight!</h4>'}); break; | ||||
| 			case 2.1: M.toast({text: '',  html: '<h4>Three of a kind!</h4>'}); break; | ||||
| 			case 3: M.toast({text: '',  html: '<h4>Four of a kind!</h4>'}); break; | ||||
| 			case 4: M.toast({text: '',  html: '<h4>Three fours!</h4>'}); break; | ||||
| 			case 5: M.toast({text: '',  html: '<h4>Two fours!</h4>'}); break; | ||||
| 			case 6: M.toast({text: '',  html: '<h4>One four!</h4>'}); 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); | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										35
									
								
								scripts/offline.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								scripts/offline.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| 	} | ||||
|   })()); | ||||
| }); | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue