mirror of https://github.com/espruino/BangleApps
Added jbm8b
parent
c7ba910aef
commit
459df6ef40
|
@ -0,0 +1,2 @@
|
|||
0.01: First working version
|
||||
0.02: Added delay in replying for dramatic effect
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"id": "jbm8b",
|
||||
"name": "Magic 8 Ball",
|
||||
"icon": "app.png",
|
||||
"description": "A simple fortune telling app",
|
||||
"tags": "game",
|
||||
"storage": [
|
||||
{
|
||||
"name": "+jbm8b",
|
||||
"url": "app.json"
|
||||
},
|
||||
{
|
||||
"name": "-jbm8b",
|
||||
"url": "app.js"
|
||||
},
|
||||
{
|
||||
"name": "*jbm8b",
|
||||
"url": "app-icon.js",
|
||||
"evaluate": true
|
||||
}
|
||||
],
|
||||
"version": "1.1.0"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("slkgRC/AF1a1WpoAWSgO//4AB/1QDCNvC4QZCGaELC4gAB/BITAAmAGCoyQGBAABMpkHC5P/8AYLl4YK/pJWPxkDC5ZLLj4YM/gYJv4YM/4YJC5v/4BiVMhUPDBz8IYpbJMPZx9JC559HPZ4AB6AYFg4YQ+CUVSxEfDCCWGn4YQSwytH/2V34YHoCtMRYMBBQ+AC4YNHLAcvZBcCBg30gFZgELZBbfH8DPB8ALHZAjfH4C2B/hWHDAg+HwC2B/yIHKwL4KoCsCDA76EDBYDDAAf8DAZaBDCy7HwF/JRLTDgBzBSox8KBAIYK6CuCdg4YM+DQBAQQAGDBZwBtVARA4YMSQILBSgwYFRgSWGgEBBQ4YMUQa6HDBnwSQPQPhgYH4CuKPhlAfJQYMCgeAHw4YK/ySD4AlIDBP8gYEC6CWG/wYP8D6GDAgkGDBjTDgALGDBn8DAcPBYzDDMY4YLSpn4DAcLUI+/cgoAD+gYDg75HIwJzBBY3wDAZ0DAAfAEIPgJwYYIOgYMFig9I6AYDEo67DVow9BDAZXH/+QEZH/wAYERIwAB1SXCUIwAEXYwAK/wYFLA4AJfAj6IABT4EcJIAJYwjIJABLGEV5QAIVoqvKVpoABl4XO/oYHhYYO+gYHgYYO8AYHPp57HAAM/C5n+C5D7Oe4ziRMRIAB34YLoAYKj7FTWB5JLAAN/JKr8LexB+PGBoABg4wWAAMvSSIAGt4XC/xIPAAkV1WVCyYA/AH4A/AH4Ai"))
|
|
@ -0,0 +1,85 @@
|
|||
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();
|
||||
|
||||
// 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"});
|
||||
|
||||
Bangle.on('lcdPower', (on) => {
|
||||
if (on) {
|
||||
Bangle.drawWidgets();
|
||||
ask();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Magic 8 Ball",
|
||||
"icon": "*jbm8b",
|
||||
"src": "-jbm8b",
|
||||
"version": "1.1.0"
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Loading…
Reference in New Issue