Merge pull request #14 from chiefdaft/dev_0.5
Dev 0.5 -- v0.05 Added a chevron to the randomly added new tiles, updated readme and imagesmaster
|
@ -2,3 +2,4 @@
|
|||
0.02: Temporary intermediate version
|
||||
0.03: Basic colors
|
||||
0.04: Bug fix score reset after Game Over, new icon
|
||||
0.05: Chevron marker on the randomly added square
|
|
@ -11,6 +11,8 @@ When two tiles with the same number are squashed together they will add up as ex
|
|||
|
||||
**3 + 3 = 4** or **C + C = D** which is a representation of **2^3 + 2^3 = 2^4 = 16**
|
||||
|
||||
After each move a new tile will be added on a random empty square. The value can be 1 or 2, and will be marked with a chevron.
|
||||
|
||||
So you can continue till you reach **1024** which equals **2^(10)**. So when you reach tile **10** you have won.
|
||||
|
||||
The score is maintained by adding the outcome of the sum of all pairs of squashed tiles (4+16+4+8 etc.)
|
||||
|
|
|
@ -17,7 +17,7 @@ const cellChars = [
|
|||
const maxUndoLevels = 4;
|
||||
const noExceptions = true;
|
||||
let charIndex = 0; // plain numbers on the grid
|
||||
|
||||
const themeBg = g.theme.bg;
|
||||
|
||||
|
||||
const scores = {
|
||||
|
@ -304,14 +304,30 @@ class Cell {
|
|||
this.previousExpVals=[];
|
||||
this.idx = idx;
|
||||
this.cb = cb;
|
||||
this.isRndm = false;
|
||||
this.ax = x0;
|
||||
this.ay = Math.floor(0.2*width+y0);
|
||||
this.bx = Math.floor(0.3*width+x0);
|
||||
this.by = Math.floor(0.5*width+y0);
|
||||
this.cx = x0;
|
||||
this.cy = Math.floor(0.8*width+y0);
|
||||
}
|
||||
getColor(i) {
|
||||
return cellColors[i >= cellColors.length ? cellColors.length -1 : i];
|
||||
}
|
||||
drawBg() {
|
||||
debug(()=>console.log("Drawbg!!"));
|
||||
if (this.isRndm == true) {
|
||||
debug(()=>console.log('Random: (ax)', this.ax));
|
||||
g.setColor(this.getColor(this.expVal).bg)
|
||||
.fillRect(this.x0, this.y0, this.x1, this.y1)
|
||||
.setColor(themeBg)
|
||||
.fillPoly([this.cx,this.cy,this.bx,this.by,this.ax,this.ay]);
|
||||
} else {
|
||||
g.setColor(this.getColor(this.expVal).bg)
|
||||
.fillRect(this.x0, this.y0, this.x1, this.y1);
|
||||
}
|
||||
}
|
||||
drawNumber() {
|
||||
if (this.expVal !== 0) {
|
||||
g.setFont(cellFonts[charIndex])
|
||||
|
@ -346,6 +362,19 @@ class Cell {
|
|||
this.cb(this.expVal);
|
||||
}
|
||||
}
|
||||
setRndmFalse() {
|
||||
this.isRndm = false;
|
||||
}
|
||||
setRndmTrue() {
|
||||
this.isRndm = true;
|
||||
}
|
||||
drawRndmIndicator(){
|
||||
if (this.isRndm == true) {
|
||||
debug(()=>console.log('Random: (ax)', this.ax));
|
||||
g.setColor(this.getColor(0).bg)
|
||||
.fillPoly(this.ax,this.ay,this.bx,this.by,this.cx,this.cy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function undoGame() {
|
||||
|
@ -387,11 +416,12 @@ function createGrid () {
|
|||
}
|
||||
}
|
||||
function messageGameOver () {
|
||||
g.setColor("#1a0d00")
|
||||
const c = (g.theme.dark) ? {"fg": "#FFFFFF", "bg": "#808080"} : {"fg": "#FF0000", "bg": "#000000"};
|
||||
g.setColor(c.bg)
|
||||
.setFont12x20(2).setFontAlign(0,0,0)
|
||||
.drawString("G A M E", middle.x+13, middle.y-24)
|
||||
.drawString("O V E R !", middle.x+13, middle.y+24);
|
||||
g.setColor("#ffffff")
|
||||
g.setColor(c.fg)
|
||||
.drawString("G A M E", middle.x+12, middle.y-25)
|
||||
.drawString("O V E R !", middle.x+12, middle.y+25);
|
||||
}
|
||||
|
@ -417,11 +447,13 @@ function addRandomNumber() {
|
|||
if (emptySquaresIdxs.length > 0) {
|
||||
let randomIdx = Math.floor( emptySquaresIdxs.length * Math.random() );
|
||||
allSquares[emptySquaresIdxs[randomIdx]].setExpVal(makeRandomNumber());
|
||||
allSquares[emptySquaresIdxs[randomIdx]].setRndmTrue();
|
||||
}
|
||||
}
|
||||
function drawGrid() {
|
||||
allSquares.forEach(sq => {
|
||||
sq.drawBg();
|
||||
// sq.drawRndmIndicator();
|
||||
sq.drawNumber();
|
||||
});
|
||||
}
|
||||
|
@ -497,7 +529,7 @@ function handlePopUpClicks(btn) {
|
|||
function resetGame() {
|
||||
g.clear();
|
||||
scores.reset();
|
||||
allSquares.forEach(sq => {sq.setExpVal(0);sq.removeUndo();});
|
||||
allSquares.forEach(sq => {sq.setExpVal(0);sq.removeUndo();sq.setRndmFalse();});
|
||||
addRandomNumber();
|
||||
addRandomNumber();
|
||||
drawGrid();
|
||||
|
@ -614,6 +646,7 @@ function runGame(dir){
|
|||
mover.nonEmptyCells(dir);
|
||||
mover.mergeEqlCells(dir);
|
||||
mover.nonEmptyCells(dir);
|
||||
allSquares.forEach(sq => {sq.setRndmFalse();});
|
||||
addRandomNumber();
|
||||
drawGrid();
|
||||
scores.check();
|
||||
|
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 4.0 KiB |
|
@ -1,7 +1,7 @@
|
|||
{ "id": "game1024",
|
||||
"name": "1024 Game",
|
||||
"shortName" : "1024 Game",
|
||||
"version": "0.04",
|
||||
"version": "0.05",
|
||||
"icon": "game1024.png",
|
||||
"screenshots": [ {"url":"screenshot.png" } ],
|
||||
"readme":"README.md",
|
||||
|
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 54 KiB |