mirror of https://github.com/espruino/BangleApps
Merge pull request #945 from nlisgo/improve-ux-add-timer
Cube Scramble: Improved UX and display solve timepull/948/head
commit
1b9477be5d
|
@ -551,8 +551,8 @@
|
||||||
{
|
{
|
||||||
"id": "cubescramble",
|
"id": "cubescramble",
|
||||||
"name": "Cube Scramble",
|
"name": "Cube Scramble",
|
||||||
"version":"0.03",
|
"version":"0.04",
|
||||||
"description": "A random scramble generator for the 3x3 Rubik's cube",
|
"description": "A random scramble generator for the 3x3 Rubik's cube with a basic timer",
|
||||||
"icon": "cube-scramble.png",
|
"icon": "cube-scramble.png",
|
||||||
"tags": "",
|
"tags": "",
|
||||||
"supports" : ["BANGLEJS","BANGLEJS2"],
|
"supports" : ["BANGLEJS","BANGLEJS2"],
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
0.01: Initial Release
|
0.01: Initial Release
|
||||||
0.02: Replace icon with one found on https://icons8.com
|
0.02: Replace icon with one found on https://icons8.com
|
||||||
0.03: Re-render icon fixing display in settings
|
0.03: Re-render icon fixing display in settings
|
||||||
|
0.04: Improved UX and display solve time
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
# Cube Scramble
|
# Cube Scramble
|
||||||
|
|
||||||
A random scramble generator for the 3x3 Rubik's cube
|
A random scramble generator for the 3x3 Rubik's cube with a basic timer.
|
||||||
|
|
||||||
## Future features
|
## Future features
|
||||||
|
|
||||||
I'm keen to complete this project with
|
I'm keen to complete this project with
|
||||||
|
|
||||||
* Add a timer
|
|
||||||
* Add the ability for times to be stored and exported
|
* Add the ability for times to be stored and exported
|
||||||
|
|
||||||
## Requests
|
## Requests
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.9 KiB |
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
// Scramble code from: https://raw.githubusercontent.com/bjcarlson42/blog-post-sample-code/master/Rubik's%20Cube%20JavaScript%20Scrambler/part_two.js
|
// Scramble code from: https://raw.githubusercontent.com/bjcarlson42/blog-post-sample-code/master/Rubik's%20Cube%20JavaScript%20Scrambler/part_two.js
|
||||||
const makeScramble = () => {
|
const makeScramble = () => {
|
||||||
const options = ["F", "F2", "F'", "R", "R2", "R'", "U", "U2", "U'", "B", "B2", "B'", "L", "L2", "L'", "D", "D2", "D'"];
|
const options = ["F", "F2", "F'", "R", "R2", "R'", "U", "U2", "U'", "B", "B2", "B'", "L", "L2", "L'", "D", "D2", "D'"];
|
||||||
|
@ -59,16 +58,36 @@ const getRandomInt = max => Math.floor(Math.random() * Math.floor(max)); // retu
|
||||||
const getRandomIntBetween = (min, max) => Math.floor(Math.random() * (max - min) + min);
|
const getRandomIntBetween = (min, max) => Math.floor(Math.random() * (max - min) + min);
|
||||||
|
|
||||||
const presentScramble = () => {
|
const presentScramble = () => {
|
||||||
g.clear();
|
showPrompt(makeScramble().join(" "), {
|
||||||
E.showMessage(makeScramble().join(" "));
|
buttons: {"solve": true, "reset": false}
|
||||||
|
}).then((v) => {
|
||||||
|
if (v) {
|
||||||
|
const start = new Date();
|
||||||
|
showPrompt(" ", {
|
||||||
|
buttons: {"stop": true}
|
||||||
|
}).then(() => {
|
||||||
|
const time = parseFloat(((new Date()).getTime() - start.getTime()) / 1000);
|
||||||
|
showPrompt(String(time.toFixed(3)), {
|
||||||
|
buttons: {"next": true}
|
||||||
|
}).then(() => {
|
||||||
|
presentScramble();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
presentScramble();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const showPrompt = (text, options = {}) => {
|
||||||
|
options.title = options.title || "cube scramble";
|
||||||
|
return E.showPrompt(text, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
|
Bangle.setLCDTimeout(0);
|
||||||
|
Bangle.setLCDPower(1);
|
||||||
presentScramble();
|
presentScramble();
|
||||||
|
|
||||||
setWatch(() => {
|
|
||||||
presentScramble();
|
|
||||||
}, BTN1, {repeat:true});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Reference in New Issue