From 80246d2398a93311aaa131886f873b54da705a66 Mon Sep 17 00:00:00 2001 From: marko Date: Wed, 23 Mar 2022 15:00:54 -0400 Subject: [PATCH] New app 2047pp --- apps/2047pp/2047pp.app.js | 129 ++++++++++++++++++++++++++++++++++++++ apps/2047pp/README.md | 6 ++ apps/2047pp/app-icon.js | 1 + apps/2047pp/app.png | Bin 0 -> 759 bytes apps/2047pp/metadata.json | 14 +++++ 5 files changed, 150 insertions(+) create mode 100644 apps/2047pp/2047pp.app.js create mode 100644 apps/2047pp/README.md create mode 100644 apps/2047pp/app-icon.js create mode 100644 apps/2047pp/app.png create mode 100644 apps/2047pp/metadata.json diff --git a/apps/2047pp/2047pp.app.js b/apps/2047pp/2047pp.app.js new file mode 100644 index 000000000..b508d8f07 --- /dev/null +++ b/apps/2047pp/2047pp.app.js @@ -0,0 +1,129 @@ + + +class TwoK { + constructor() { + this.b = Array(4).fill().map(() => Array(4).fill(0)); + this.score = 0; + this.cmap = {0: "#caa", 2:"#ccc", 4: "#bcc", 8: "#ba6", 16: "#e61", 32: "#d20", 64: "#d00", 128: "#da0", 256: "#ec0", 512: "#dd0"}; + } + drawBRect(x1, y1, x2, y2, th, c, cf) { + g.setColor(c); + for (i=0; i 4) g.setColor(1, 1, 1); + else g.setColor(0, 0, 0); + g.setFont("Vector", bh*(b>8 ? (b>64 ? (b>512 ? 0.32 : 0.4) : 0.6) : 0.7)); + if (b>0) g.drawString(b.toString(), xo+(x+0.5)*bw+1, yo+(y+0.5)*bh); + } + } + shift(d) { // +/-1: shift x, +/- 2: shift y + var crc = E.CRC32(this.b.toString()); + if (d==-1) { // shift x left + for (y=0; y<4; ++y) { + for (x=2; x>=0; x--) + if (this.b[y][x]==0) { + for (i=x; i<3; i++) this.b[y][i] = this.b[y][i+1]; + this.b[y][3] = 0; moved = true; + } + for (x=0; x<3; ++x) + if (this.b[y][x]==this.b[y][x+1]) { + this.score += 2*this.b[y][x]; + this.b[y][x] += this.b[y][x+1]; + for (j=x+1; j<3; ++j) this.b[y][j] = this.b[y][j+1]; + this.b[y][3] = 0; moved = true; + } + } + } + else if (d==1) { // shift x right + for (y=0; y<4; ++y) { + for (x=1; x<4; x++) + if (this.b[y][x]==0) { + for (i=x; i>0; i--) this.b[y][i] = this.b[y][i-1]; + this.b[y][0] = 0; + } + for (x=3; x>0; --x) + if (this.b[y][x]==this.b[y][x-1]) { + this.score += 2*this.b[y][x]; + this.b[y][x] += this.b[y][x-1] ; + for (j=x-1; j>0; j--) this.b[y][j] = this.b[y][j-1]; + this.b[y][0] = 0; + } + } + } + else if (d==-2) { // shift y down + for (x=0; x<4; ++x) { + for (y=1; y<4; y++) + if (this.b[y][x]==0) { + for (i=y; i>0; i--) this.b[i][x] = this.b[i-1][x]; + this.b[0][x] = 0; + } + for (y=3; y>0; y--) + if (this.b[y][x]==this.b[y-1][x] || this.b[y][x]==0) { + this.score += 2*this.b[y][x]; + this.b[y][x] += this.b[y-1][x]; + for (j=y-1; j>0; j--) this.b[j][x] = this.b[j-1][x]; + this.b[0][x] = 0; + } + } + } + else if (d==2) { // shift y up + for (x=0; x<4; ++x) { + for (y=2; y>=0; y--) + if (this.b[y][x]==0) { + for (i=y; i<3; i++) this.b[i][x] = this.b[i+1][x]; + this.b[3][x] = 0; + } + for (y=0; y<3; ++y) + if (this.b[y][x]==this.b[y+1][x] || this.b[y][x]==0) { + this.score += 2*this.b[y][x]; + this.b[y][x] += this.b[y+1][x]; + for (j=y+1; j<3; ++j) this.b[j][x] = this.b[j+1][x]; + this.b[3][x] = 0; + } + } + } + return (E.CRC32(this.b.toString())!=crc); + } + addDigit() { + var d = Math.random()>0.9 ? 4 : 2; + var id = Math.floor(Math.random()*16); + while (this.b[Math.floor(id/4)][id%4] > 0) id = Math.floor(Math.random()*16); + this.b[Math.floor(id/4)][id%4] = d; + } +} + +function dragHandler(e) { + if (e.b && (Math.abs(e.dx)>7 || Math.abs(e.dy)>7)) { + var res = false; + if (Math.abs(e.dx)>Math.abs(e.dy)) { + if (e.dx>0) res = twok.shift(1); + if (e.dx<0) res = twok.shift(-1); + } + else { + if (e.dy>0) res = twok.shift(-2); + if (e.dy<0) res = twok.shift(2); + } + if (res) twok.addDigit(); + twok.render(); + } +} + +var twok = new TwoK(); +twok.addDigit(); twok.addDigit(); +twok.render(); +Bangle.on("drag", dragHandler); diff --git a/apps/2047pp/README.md b/apps/2047pp/README.md new file mode 100644 index 000000000..e685946c1 --- /dev/null +++ b/apps/2047pp/README.md @@ -0,0 +1,6 @@ + +# Game of 2047pp (2047++) + +Tile shifting game inspired by the well known 2048 game. Also very similar to another Bangle game, Game1024. + +Attempt to combine equal numbers by swiping left, right, up or down. diff --git a/apps/2047pp/app-icon.js b/apps/2047pp/app-icon.js new file mode 100644 index 000000000..4086d1879 --- /dev/null +++ b/apps/2047pp/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A31gAeFtoxPF9wujGBYQG1YAWF6ur5gAYGIovOFzIABF6ReaMAwv/F/4v/F7ejv9/0Yvq1Eylksv4vqvIuBF9ZeDF9ZeBqovr1AsB0YvrLwXMF9ReDF9ZeBq1/v4vBqowKF7lWFYIAFF/7vXAAa/qF+jxB0YvsABov/F/4v/F6WsF7YgEF5xgaLwgvPGIQAWDwwvQADwvJGEguKF+AxhFpoA/AH4A/AFI=")) \ No newline at end of file diff --git a/apps/2047pp/app.png b/apps/2047pp/app.png new file mode 100644 index 0000000000000000000000000000000000000000..d1fb4a5e5cbadce3da7b36806d4907f680f8f1bb GIT binary patch literal 759 zcmVYCuD-J|F04S(qype>Ll^oVPK(#&(MEqX}dr+-4N41U&D6G<#pk8p=ry~PL z8P~wDv0Fxk@G(D*-Esf`5DS+uaYFpJB+Wpns^Zb}E7&tzFF7%tm102J6nd69|4+P3 zr1VfMt5{y0fI>`0^KD2mu=F8{y6M673*Til--d7lyX64hte$~F4EL^Xh;F_M;RY5n zQPi8Q(T|*z{|6UpV5c0w+w9;*9}v8ZE@h%j4t73gCg!Qfe`}$Ac#sB~}C%=m9 zQmlcEAIAXzTR($HE?;WPt>nU3$%Ta*5c>_tUp2cB`Ud77yzh$Lczg#y>rX6t^Z|D> zcQA?REP&Q#P6pBq$e1?!8Tl#X8W=W?3|OSe*3omHjttb47#RG02|5f6e$ zObTJ!ml%i%20ylab9U#WUDz$7W@n({nZhq+5~`IO*5Pi07qm053E*;P(4-Kmo@>1; z>;uNw7hc?M3Z*1!=?Nlw%8PRi7>4l#z$>YW4#!KwFcx?T+e^N5I_>#$tusSJ+zSuc p5YZ-MEM*wRg54#bi;K&M^BdjW!v$Q*XjK3J002ovPDHLkV1lLySIGbX literal 0 HcmV?d00001 diff --git a/apps/2047pp/metadata.json b/apps/2047pp/metadata.json new file mode 100644 index 000000000..7c120efec --- /dev/null +++ b/apps/2047pp/metadata.json @@ -0,0 +1,14 @@ +{ "id": "2047pp", + "name": "2047pp", + "shortName":"2047pp", + "icon": "app.png", + "version":"0.01", + "description": "Bangle version of a tile shifting game", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "tags": "game", + "storage": [ + {"name":"2047pp.app.js","url":"2047pp.app.js"}, + {"name":"2047pp.img","url":"app-icon.js","evaluate":true} + ] +}