This commit is contained in:
Saw, Hansly Kendrich 2022-09-14 15:46:57 +08:00
parent 02ce8b3e51
commit 1d16cfc44b
11 changed files with 180 additions and 4 deletions

View file

@ -2,9 +2,77 @@
<head>
<title>RollDice</title>
<link href="node_modules/@materializecss/materialize/dist/css/materialize.css" rel="stylesheet" />
<link href="node_modules/@mdi/font/css/materialdesignicons.css" rel="stylesheet" />
<script src="node_modules/@materializecss/materialize/dist/js/materialize.js"></script>
<script src="scripts/roll.js"></script>
<script src="scripts/interface.js"></script>
</head>
<body>
<body class="red darken-4">
<nav>
<div class="nav-wrapper red">
<ul id="nav-mobile" class="left"><a class="brand-logo">
<li><a class="waves-effect waves-light"><i class="left mdi mdi-dice-4"></i><strong style="font-size: 150%;">RollDice</strong></a></li>
</ul>
<ul id="nav-mobile" class="right">
<li><a class="waves-effect waves-light"><i class="left mdi mdi-reload"></i><span class="right hide-on-med-and-down">Spin</span></a></li>
<li><a class="waves-effect waves-light"><i class="left mdi mdi-information-outline"></i><span class="right hide-on-med-and-down">About</span></a></li>
</ul>
</div>
</nav>
<main>
<side id="interface_below_buttons">
<div class="fixed-action-btn">
<button class="btn-floating btn-large waves-effect waves-light orange" title="Spin"><i class="left mdi mdi-format-rotate-90"></i></button>
</div>
</side>
<section>
<div class="row">
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-1">Card Title</span>
</div>
</div>
</div>
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-2">Card Title</span>
</div>
</div>
</div>
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-3">Card Title</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-4">Card Title</span>
</div>
</div>
</div>
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-5">Card Title</span>
</div>
</div>
</div>
<div class="col s12 m2">
<div class="card">
<div class="card-content">
<span class="card-title" id="dice-6">Card Title</span>
</div>
</div>
</div>
</div>
</section>
</main>
</body>
</html>

Binary file not shown.

BIN
media/beep.mp3 Normal file

Binary file not shown.

BIN
media/ding.mp4 Normal file

Binary file not shown.

BIN
media/tada.mp3 Normal file

Binary file not shown.

BIN
node_modules/.DS_Store generated vendored

Binary file not shown.

5
node_modules/.package-lock.json generated vendored
View file

@ -8,6 +8,11 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@materializecss/materialize/-/materialize-1.1.0.tgz",
"integrity": "sha512-W2MrDC8mzpMWyP2OpS0RWTWGcLiRRBz7kn2E9TsbardPyVNFdoNvXq5sLy3NcEfAlACc1+L7Q95+pBuUX44dRg=="
},
"node_modules/@mdi/font": {
"version": "7.0.96",
"resolved": "https://registry.npmjs.org/@mdi/font/-/font-7.0.96.tgz",
"integrity": "sha512-rzlxTfR64hqY8yiBzDjmANfcd8rv+T5C0Yedv/TWk2QyAQYdc66e0kaN1ipmnYU3RukHRTRcBARHzzm+tIhL7w=="
}
}
}

13
package-lock.json generated
View file

@ -9,13 +9,19 @@
"version": "0.1.0",
"license": "ISC",
"dependencies": {
"@materializecss/materialize": "^1.1.0"
"@materializecss/materialize": "^1.1.0",
"@mdi/font": "^7.0.96"
}
},
"node_modules/@materializecss/materialize": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@materializecss/materialize/-/materialize-1.1.0.tgz",
"integrity": "sha512-W2MrDC8mzpMWyP2OpS0RWTWGcLiRRBz7kn2E9TsbardPyVNFdoNvXq5sLy3NcEfAlACc1+L7Q95+pBuUX44dRg=="
},
"node_modules/@mdi/font": {
"version": "7.0.96",
"resolved": "https://registry.npmjs.org/@mdi/font/-/font-7.0.96.tgz",
"integrity": "sha512-rzlxTfR64hqY8yiBzDjmANfcd8rv+T5C0Yedv/TWk2QyAQYdc66e0kaN1ipmnYU3RukHRTRcBARHzzm+tIhL7w=="
}
},
"dependencies": {
@ -23,6 +29,11 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@materializecss/materialize/-/materialize-1.1.0.tgz",
"integrity": "sha512-W2MrDC8mzpMWyP2OpS0RWTWGcLiRRBz7kn2E9TsbardPyVNFdoNvXq5sLy3NcEfAlACc1+L7Q95+pBuUX44dRg=="
},
"@mdi/font": {
"version": "7.0.96",
"resolved": "https://registry.npmjs.org/@mdi/font/-/font-7.0.96.tgz",
"integrity": "sha512-rzlxTfR64hqY8yiBzDjmANfcd8rv+T5C0Yedv/TWk2QyAQYdc66e0kaN1ipmnYU3RukHRTRcBARHzzm+tIhL7w=="
}
}
}

View file

@ -18,6 +18,7 @@
"author": "buzz-lightsnack-2007",
"license": "ISC",
"dependencies": {
"@materializecss/materialize": "^1.1.0"
"@materializecss/materialize": "^1.1.0",
"@mdi/font": "^7.0.96"
}
}

5
scripts/interface.js Normal file
View file

@ -0,0 +1,5 @@
let soundEffects = {
'ding': new Audio('media/ding.mp4'),
'fallout': new Audio('media/Shells_falls-Marcel-829263474.mp3'),
'tada': new Audio('media/tada.mp3')
}

86
scripts/roll.js Normal file
View file

@ -0,0 +1,86 @@
/* https://en.wikipedia.org/wiki/Bo_Bing_(game) */
function randomNumber (minimum, maximum, times = 1) {
let resultNumber = 0;
for (currentRandom = 0; currentRandom < times; currentRandom++) {
resultNumber = Math.floor(Math.random() * (maximum - minimum) + minimum);
};
return resultNumber;
};
function rollDice(times = 1) {
let value_dices = [];
let value_current = 0;
let dices_amount_current = value_dices.length;
for (rolls = 0; rolls < times; rolls++) {
for (dices_max = 6; dices_amount_current < dices_max; dices_amount_current = value_dices.length) {
value_current = randomNumber(1, 6);
if (randomNumber(1, 2) == 1) {
value_dices.push(value_current);
} else {
value_dices.unshift(value_current);
};
};
};
return value_dices;
};
function rollDiceWithResults() {
let value_dices = rollDice();
let value_current = 0;
let value_dices_numbers = {
'one': 0,
'two': 0,
'three': 0,
'four': 0,
'five': 0,
'six': 0
};
/* The first dice is always the zeroth dice! */
for (diceNumber = 0; diceNumber < value_dices.length; diceNumber++) {
value_current = value_dices[diceNumber];
switch (value_current) {
case 1: value_dices_numbers.one++; break;
case 2: value_dices_numbers.two++; break;
case 3: value_dices_numbers.three++; break;
case 4: value_dices_numbers.four++; break;
case 5: value_dices_numbers.five++; break;
case 6: value_dices_numbers.six++; break;
};
};
let result_number = 0;
/* The highest of each place starts as an integer, the rest is an increment by .1. */
if ((value_dices_numbers.four == value_dices.length) || (value_dices_numbers.one == value_dices.length)) {
/* Six Fours */
result_number = 1;
if (value_dices_numbers.one > value_dices_numbers.four) {
/* Six Ones */
result_number = result_number + 0.1;
};
} else if (value_dices.every( (val, i, arr) => val === arr[0] )) {
/* Six of a Kind */
result_number = 1.2;
} else if (value_dices_numbers.four == 5) {
/* Five Fours */
result_number = 1.3;
} else if ((value_dices_numbers.one == 5) || (value_dices_numbers.two == 5) || (value_dices_numbers.three == 5) || (value_dices_numbers.five == 5) || (value_dices_numbers.six == 5)) {
/* Five of a Kind */
result_number = 1.4;
} else if (value_dices_numbers.four == 4) {
/* Four Fours */
result_number = 1.5;
} else if (value_dices_numbers.every( (val, i, arr) => val === arr[0] )) {
result_number = 2;
};
let results = {'dice': value_dices,
'result': result_number};
return results;
}