Merge pull request #421 from johanbove/master

New App: Magic 8Ball
pull/424/head
Gordon Williams 2020-05-15 13:36:46 +01:00 committed by GitHub
commit 14c1f04d0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 104 additions and 1 deletions

View File

@ -1747,5 +1747,18 @@
{"name":"dotmatrixclock.app.js","url":"app.js"},
{"name":"dotmatrixclock.img","url":"dotmatrixclock-icon.js","evaluate":true}
]
},
{
"id": "jbm8b",
"name": "Magic 8 Ball",
"shortName": "Magic 8 Ball",
"icon": "app.png",
"description": "A simple fortune telling app",
"tags": "game",
"storage": [
{ "name": "jbm8b.app.js", "url": "app.js" },
{ "name": "jbm8b.img", "url": "app-icon.js", "evaluate": true }
],
"version": "0.03"
}
]

View File

@ -11,4 +11,4 @@
{"name":"7chname.app.js","url":"app.js"},
{"name":"7chname.img","url":"app-icon.js","evaluate":true}
]
}
}

3
apps/jbm8b/Changelog Normal file
View File

@ -0,0 +1,3 @@
0.01: First working version
0.02: Added delay in replying for dramatic effect
0.03: Fixed apps.json entry

1
apps/jbm8b/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwhBC/AGMrq2B1gAEwNWlYthq2s64AKGYIydFpoAEGLUrFqIADqxcXFqhiDFymBFy7GCF1owTRjCSVlYudeiGsF7/XlaNqSKBeP1mBwJxQMBReO1gaEleBMDBLN1hAC1hhBAoIwNCwQAGlZINqxvFGAIXOSBAXQN4hPBC5yQIVBxfBCAgvQSBC+NFAYRDMwJHOF654DqxkBYooALF6+sbIhkEF8Z3CRIWBR6AvXFAzvQF6wnIYQJgNd5AWNdoLoGBBAvPO5pfYH4IvUUwS/GVBzXBYCpHCq2s1mBDwKOWDwRgNPAwVVMCRLCwIABCZ6OJJSAATLxZgRACJeLAAMrFz9WFxiRgRpoADwIub1guQGDmsXhqSfRiL0G1jqkMRYxRwKLUGK2sFryVEq2B1gAEwNWFkIA/AH4A/AH4AQ"))

80
apps/jbm8b/app.js Normal file
View File

@ -0,0 +1,80 @@
const affirmative = [
'It is\ncertain.',
'It is\ndicededly\nso.',
'Without\na doubt.',
'Yes\ndefinitely.',
'You may\nrely\non it.',
'As I see,\nit yes.',
'Most\nlikely.',
'Outlook\ngood.',
'Yes.',
'Signs point\nto yes.'
];
const nonCommittal = [
'Reply hazy,\ntry again.',
'Ask again\nlater.',
'Better not\ntell you\nnow.',
'Cannot\npredict\nnow.',
'Concentrate\nand\nask again.'
];
const negative = [
'Don\'t\ncount on it.',
'My reply\nis no.',
'My sources\nsay no.',
'Outlook\nis not\nso\ngood.',
'Very\ndoubtful.'
];
const title = 'Magic 8 Ball';
const answers = [affirmative, nonCommittal, negative];
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function predict() {
// affirmative, negative or non-committal
let max = answers.length;
const a = Math.floor(getRandomArbitrary(0, max));
// sets max compared to answer category
max = answers[a].length;
const b = Math.floor(getRandomArbitrary(0, max));
// get the answer
const response = answers[a][b];
return response;
}
function draw(msg) {
// console.log(msg);
g.clear();
E.showMessage(msg, title);
}
function reply(button) {
const theButton = (typeof button === 'undefined' || isNaN(button)) ? 1 : button;
const timer = Math.floor(getRandomArbitrary(0, theButton) * 1000);
// Thinking...
draw('...');
setTimeout('draw(predict());', timer);
}
function ask() {
draw('Ask me a\nYes or No\nquestion\nand\ntouch the\nscreen');
}
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
ask();
// Event Handlers
Bangle.on('touch', (button) => reply(button));
setWatch(ask, BTN1, { repeat: true, edge: "falling" });
setWatch(reply, BTN3, { repeat: true, edge: "falling" });
// Back to launcher
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });

6
apps/jbm8b/app.json Normal file
View File

@ -0,0 +1,6 @@
{
"name": "Magic 8 Ball",
"icon": "*jbm8b",
"src": "-jbm8b",
"version": "1.1.0"
}

BIN
apps/jbm8b/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB