feat: multiple player support

master
Michael Salaverry 2021-12-11 20:29:54 +02:00
parent 24d66cb4a0
commit d8c41b78a2
No known key found for this signature in database
GPG Key ID: 438AB878C0FB04CC
9 changed files with 108 additions and 44 deletions

View File

@ -57,11 +57,12 @@
{ "id": "golfscore", { "id": "golfscore",
"name": "Golf Score", "name": "Golf Score",
"shortName":"golfscore", "shortName":"golfscore",
"version":"0.01", "version":"0.02",
"description": "keeps track of strokes during a golf game", "description": "keeps track of strokes during a golf game",
"icon": "app.png", "icon": "app.png",
"tags": "outdoors", "tags": "outdoors",
"supports" : ["BANGLEJS2"], "allow_emulator": true,
"supports" : ["BANGLEJS","BANGLEJS2"],
"readme": "README.md", "readme": "README.md",
"storage": [ "storage": [
{"name":"golfscore.app.js","url":"app.js"}, {"name":"golfscore.app.js","url":"app.js"},

View File

@ -1 +1,2 @@
0.01: New App! 0.01: New App!
0.02: multiple player score support

View File

@ -1,25 +1,37 @@
# App Name # Golf Score
Describe the app... Lets you keep track of strokes during a game of Golf.
Add screen shots (if possible) to the app folder and link then into this file with ![](<name>.png) ![](mainmenu.png)
![](setupmenu.png)
![](scorecard.png)
![](holemenu.png)
## Usage ## Usage
Describe how to use it 1. Open the app,
1. scroll to setup
2. set the number of holes (18 by default, but can be configured)
3. set the number of players (4 by default, but can be 1-20)
4. click back
5. scroll to a hole (hole 1)
6. scroll to a player and set the number of strokes they took (repeat as needed)
7. click next hole and repeat #6 and #7 as needed; or click back
8. at any time, check the score card for a sum total of all the strokes for each player
## Features ## Features
Name the function Track strokes for multiple players (1-20)
Set number of holes on course
## Controls ## Controls
Name the buttons and what they are used for N/A
## Requests ## Requests
Name who should be contacted for support/update requests Michael Salaverry (github.com/barakplasma)
## Creator ## Creator
Your name Michael Salaverry

View File

@ -1,62 +1,113 @@
// @ts-check
// @ts-ignore
const menu = require("graphical_menu"); const menu = require("graphical_menu");
/**
* @type {{showMenu: (config) => void}}
*/
let E;
/**
* @type {{clear: () => void}}
*/
let g;
let holes_count = 18; let holes_count = 18;
let course = new Array(holes_count).fill(0); let player_count = 4;
let total_strokes = 0; /**
* @type {number[][]}
*/
let course = new Array(holes_count).map(() => new Array(player_count).fill(0));
const mainmenu = { const main_menu = {
"": { "": {
"title": "-- Golf --" "title": "-- Golf --"
}, },
"Setup": function () { E.showMenu(setup_menu); },
"Score Card": function () {
calculate_score();
E.showMenu(score_card);
},
};
function calculate_score() {
let scores = course.reduce((acc, hole) => {
hole.forEach((stroke_count, player) => {
acc[player] = acc[player]+stroke_count;
});
return acc;
}, new Array(player_count).fill(0));
score_card = {
"": {
"title": "score card"
},
"< Back": function () { E.showMenu(main_menu); },
};
for (let player = 0; player < player_count; player++) {
score_card["Player - " + (player + 1)] = {
value: scores[player]
};
}
}
let score_card = {};
const setup_menu = {
"": {
"title": "-- Golf Setup --"
},
"Holes": { "Holes": {
value: holes_count, value: holes_count,
min: 1, max: 20, step: 1, wrap: true, min: 1, max: 20, step: 1, wrap: true,
onchange: v => { holes_count = v; add_holes(); } onchange: v => { holes_count = v; add_holes(); }
}, },
"Total Strokes": { "Players": {
value: total_strokes, value: player_count,
min: 1, max: 10, step: 1, wrap: true,
onchange: v => { player_count = v; }
}, },
"< Back": function () { E.showMenu(main_menu); },
}; };
function updateTotalStrokes() { function inc_hole(i, player) { return function (v) { course[i][player] = v; }; }
total_strokes = course.reduce((acc, strokes) => acc + strokes, 0);
mainmenu["Total Strokes"].value = total_strokes;
}
function inc_hole(i) { return function (v) { course[i] = v; updateTotalStrokes(); }; }
function add_holes() { function add_holes() {
for (let j = 0; j < 100; j++) { for (let j = 0; j < 20; j++) {
delete mainmenu["Hole - " + (j + 1)]; delete main_menu["Hole - " + (j + 1)];
} }
for (let i = 0; i < holes_count; i++) { for (let i = 0; i < holes_count; i++) {
course[i] = 0; course[i] = new Array(player_count).fill(0);
mainmenu["Hole - " + (i + 1)] = hole_menu(i); main_menu["Hole - " + (i + 1)] = goto_hole_menu(i);
} }
E.showMenu(mainmenu); E.showMenu(main_menu);
}
function goto_hole_menu(i) {
return function () {
E.showMenu(hole_menu(i));
};
} }
function hole_menu(i) { function hole_menu(i) {
return function () { let menu = {
E.showMenu(submenu(i));
};
}
function submenu(i) {
return {
"": { "": {
"title": `-- Hole ${i + 1}--` "title": `-- Hole ${i + 1}--`
}, },
"strokes:": { "Next hole": goto_hole_menu(i + 1),
value: course[i], "< Back": function () { E.showMenu(main_menu); },
min: 1, max: 20, step: 1, wrap: true,
onchange: inc_hole(i)
},
"Next hole": hole_menu(i + 1),
"< Back": function () { E.showMenu(mainmenu); },
}; };
for (let player = 0; player < player_count; player++) {
menu[`player - ${player + 1}`] = {
value: course[i][player],
min: 1, max: 20, step: 1, wrap: true,
onchange: inc_hole(i, player)
};
}
return menu;
} }
// @ts-ignore
g.clear(); g.clear();
add_holes(); add_holes();
E.showMenu(mainmenu);

BIN
apps/golfscore/holemenu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
apps/golfscore/mainmenu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,4 +1,3 @@
0.01: New App! 0.01: New App!
0.02: using TS and rollup to bundle 0.02: using TS and rollup to bundle
0.03: bug fixes and support bangle 1 0.03: bug fixes and support bangle 1
0.04: don't allow date to change & docs