Merge pull request #1244 from psbest/master

add changes mmind app
pull/1260/head
Gordon Williams 2022-01-10 08:58:12 +00:00 committed by GitHub
commit 594d944dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 266 additions and 0 deletions

View File

@ -5133,6 +5133,24 @@
]
},
{
"id": "mmind",
"name": "Classic Mind Game",
"shortName":"Master Mind",
"icon": "mmind.png",
"version":"0.01",
"description": "This is the classic game for masterminds",
"screenshots": [{"url":"screenshot_mmind.png"}],
"type": "app",
"tags": "game",
"readme":"README.md",
"supports": ["BANGLEJS2"],
"allow_emulator": true,
"storage": [
{"name":"mmind.app.js","url":"mmind.app.js"},
{"name":"mmind.img","url":"mmind.icon.js","evaluate":true}
]
},
{
"id": "presentor",
"name": "Presentor",
"version": "3.0",

1
apps/mmind/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: First release

31
apps/mmind/README.md Normal file
View File

@ -0,0 +1,31 @@
# Mastermind
Play the classic mind game mastermind on your Bangle 2.
![](screenshot_mmind.png)
## Game
The game will start when run.
Four colors pins are randomly chosen and kept secret.
You need to find the secret by scoring your choice within 6 turns.
The game makes use of touch features.
## Play
Select one of the dots, the color menu will show, select a colour for the pin.
If all pins are chosen with a color the red button will turn green.
Hit the green button and your play will be scored and listed from the top.
The first digit shows the number of pins with the correct color and in the right place.
The second digit gives the number of pins with the correct color but in the wrong place.
There are six turns to get the correct secret.
The blue button will start a new game.
## Requests
This is the first version, things to add are:
Add a menu to change game options like the number of colors, allow double colors, 5 pins per row. Add feature to drag screen up and down to see more scores. Timer and high score.
Any other fearures or remarks, let me know @psbest.
## Creator
This game is created by Peter Slendebroek.

198
apps/mmind/mmind.app.js Normal file
View File

@ -0,0 +1,198 @@
//MMind
//set vars
const H = g.getWidth();
const W = g.getHeight();
var touch_actions = [];
var cols = ["#FF0000","#00FF00","#0000FF", "#FF00FF", "#FFFF00", "#00FFFF", "#000000","#FFFFFF"];
var turn = 0;
var col_menu = false;
//pinsRow = 6;
//pinsThick = 10;
//pinsRow = 5;
//pinsThick = 10;
var pinsRow = 4;
var pinsThick = 10;
var play = [-1, -1, -1, -1];
var pinsCol = 5;
var playx = -1;
var sx = (W - 30 )/pinsRow;
var sy = (H - 20 )/7;
var touch_actions = [];
var secret = [];
var secret_no_dub = true;
var endgame = false;
g.clear();
g.setColor("#FFFFFF");
g.fillRect(0, 0, H, W);
g.setFont("Vector12",45);
function draw() {
touch_actions = [];
g.clear();
g.setColor("#FFFFFF");
g.fillRect(0, 0, H, W);
g.setColor("#000000");
//draw scores
for (y=0;y<game.length;y+=1) {
pp = game[y][0];
ps = game[y][1];
g.setColor("#000000");
//g.fillRect(W-30,10, W-30, 15);
g.setColor("#000000");
g.setFont("Vector30",10);
g.drawString(ps[0],W-31,y*sy+8);
g.setColor("#000000");
g.drawString(ps[1],W-15,y*sy+8);
g.setColor("#000000");
for (x=0;x<pinsRow;x+=1) {
xx = sx*x + pinsThick + 5;
yy = sy*y+20;
xc = pp[x];
g.setColor(cols[xc]);
g.fillCircle(xx,yy , pinsThick );
g.setColor("#000000");
g.drawCircle(xx,yy,pinsThick+1);
g.drawCircle(xx,yy,pinsThick);
}
}
//draw play input
for (k=0; k<pinsRow; k+=1){
xx = sx*k + pinsThick + 5;
yy = sy*7;
touch_actions.push([[xx-pinsThick-5, yy-pinsThick-10, xx+pinsThick+5, yy+pinsThick+20],[1,k]]);
if (play[k] < 0) {
//col not choisen, draw small dot
g.setColor("#000000");
g.fillCircle(xx,yy , 3 );
} else {
g.setColor(cols[play[k]]);
g.fillCircle(xx,yy , pinsThick );
}
}
// draw action button
// score, men
if (!endgame) {
if (col_menu) {
draw_col_choice();
} else {
// check if all pins are set yet
if (Math.min.apply(null,play) < 0) {
g.setColor("#FF0000");
} else {
g.setColor("#00FF00");
touch_actions.push([[W-30, H-30,192, 190], [3,1]]);
}
g.fillRect(W-30, H-30, W-1, H-10);
}
} else {
g.setColor("#0000FF");
touch_actions.push([[W-30, H-30,192, 190], [4,1]]);
g.fillRect(W-30, H-30, W-1, H-10);
}
}
function get_secret() {
//secret=[];
for (i=0; i<pinsRow; i+=1) {
s = Math.round(Math.random()*pinsCol);
if (secret_no_dub)
while(secret.indexOf(s) >= 0) s = Math.round(Math.random()*pinsCol);
secret[i]= s;
}
}
function score() {
bScore = 0;
wScore = 0;
for (i=0; i<pinsRow; i+=1) {
if (secret[i] == play[i]) {
bScore +=1;
}
else {
for (s=0; s<pinsRow; s+=1) {
if (secret[i] == play[s]) {
wScore +=1;
break;
}
}
}
}
return([bScore, wScore]);
}
function draw_col_choice(){
var cc = g.getColor();
var boxw = 30;
var boxh = H/pinsRow-20;
for (i=0; i<=pinsCol; i+=1) {
g.setColor(cols[i]);
g.fillRect(W-boxw, i*boxh, W-1, i*boxh+boxh);
touch_actions.push([[150, i*boxh, 191, i*boxh+boxh], [2,i]]);
g.setColor(cc);
}
}
Bangle.on('touch', function(zone,e) {
//console.log(e.x, e.y);
// check touch actions array to see what to do
for(i=0; i<touch_actions.length; i+=1) {
if (e.x > touch_actions[i][0][0] && e.x < touch_actions[i][0][2] &&
e.y > touch_actions[i][0][1] && e.y < touch_actions[i][0][3]) {
// a action is hit, add acctions here, todo: start, stop, new, etc.
switch (touch_actions[i][1][0]) {
case 1:
//get pins col menu
col_menu = 1;
playx = touch_actions[i][1][1];
break;
case 2:
//copy choice col to play
play[playx] = touch_actions[i][1][1];
col_menu = 0;
break;
case 3:
//score play
var sc;
sc = score();
game.push([play, sc]);
play = [-1,-1,-1,-1];
turn+=1;
if (turn==6 || sc[0]==pinsRow) {
play = secret;
col_menu = 0;
endgame = true;
}
break;
case 4:
//new game
play = [-1,-1,-1,-1];
game = [];
endgame=false;
break;
}
}
}
//console.log(touch_actions[i][1][0], touch_actions[i][1][1]);
draw();
}
);
game = [];
get_secret();
draw();
//Bangle.loadWidgets();
//Bangle.drawWidgets();

1
apps/mmind/mmind.icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+64A/AEOBq2sBAusqwJHCaQFDAYlP2m0yGBCIkSj0eiWHBIkDgsFgYTE01v3O5t4mC1krgAEBq0ACYQuCAANsHIcxFwIwCEocsFwIwCBIYuCAANQF4QwBOgQABAgNIF4ZgELwQvCHIcCF4cEKwYvEt45DF4QwCL5YvFL5ITDF6OstheCvTjEjAuBjDJFX4UEq4TEyguBygTEF4dWBIeskkkqwQDDgUGgwaEBIUBgITHkslCYeBd4MrqwDBAgIuBcwRVGNIVs0oJEv3S6V+CYmIisjkcVZAYpBgDyBAAJFBFwTlGZIolDqouBGAQJDFwQABmRfCFAICCGwXXhgvDMAheCfI1UF4eoKwYvEiovHSoJfLF4pfJCYYvN1gwBAYMSLwVcbQmQFwOQZIq/C1GACYkcFwMcCYQoCLYNWF4KPBDgNWmIkEBIVPp5TDBIdWqoTHmUyCYlWRQTwCD4wA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AHmy2QJH6PRBI/Q6AkOCAIAFBINDjwABGInR3+53O/GIu72gABGJnQCAQAE69oFwQABCYfFFwIwCBIfCDIe7FIus1gvXLwQACLw4aCAAkAgAvcL4gvLq1WF5uyFwdoCYfLF4fLDpHCX6owBtFoxoUF6PF4ruFDwPC4XJFxbSCAAwVNAH4ARA"))

17
apps/mmind/mmind.info Normal file
View File

@ -0,0 +1,17 @@
{
"id": "mmind",
"name": "Classic Mind Game",
"shortName":"Master Mind",
"icon": "mmind.png",
"version":"0.01",
"description": "This is the classic game for masterminds",
"type": "game",
"tags": "mastermind, game, classic",
"readme":"README.md",
"supports": ["BANGLEJS2"],
"allow_emulator": true,
"storage": [
{"name":"mmind.app.js","url":"mmind.app.js"},
{"name":"mmind.img","url":"mmind.icon.js","evaluate":true}
]
}

BIN
apps/mmind/mmind.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB