Skip to content

Commit

Permalink
``
Browse files Browse the repository at this point in the history
  • Loading branch information
fc01 authored and fc01 committed Aug 5, 2017
1 parent ef7cac5 commit c1522fe
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# game1k


## [Play It Here](https://fc01.github.io/game1k)

## html
```html
<canvas id="c" width="300" height="500"></canvas>
```


## js
```js
_="c=c.getCt'2d'Wc.ft=' px Tahoma';u=tUs=wQrP54gOhsl('+v*35+', %,'+n+'%)'Iqzpz9y:zyIzon,yIzn=t;Ikj!#={y:~~(n/6),x:n%6I}Ikeydownv=zkeyCode;Z(w=vK650 187 2683 383?3:2)IhOrgba(LLL0.2)';GLL30L0Wt;eP6uQdQr.forEach(Ax=n%6;jNZw<0XV$YJV$YJA=_-1_-3 1:0;j_-2XHY+3$YJv)V$VJ}Y$v=V+AJHs=x;}vZB98WDZN+sZn<51+s)q(Y${9y:1Li:Math.random()>0.52,m:Ll:0},98WjvXj_3XY]Uj!#Xr[V]*6+x$v;B9V])}D5Z#Z)B.9.yWj6Z#Z!X#U D4Xfor(iUi<(xK0||xK54WiXA=[6,1,7,-5Ja=Y+b=Y-jaZbZaZbUk(a,nWk(b,nWu=15;}NZu!=15Xu=27}!(NZ7Zt% >20)Xf=(t-zn)/10;jf>1)fQzx=@xx-@xzy=@yy-@yx=*zx;y=4-*zy;i= ;65WG9y,5LW20Wc^T ,x2,y+ )}}}Ww=w<0?2:||7?w:_14?u:6?3:w;requestAnimatiFrame(h)Ih()=(v,n,y,A)=>{zv.jif(_wK^.fillZ&&Yr[nX){W);Ve[xU=0;Q=1;P=new Array(Oc^Style='Nn>47L0,K==J];I};HjdZvXdUGc^Rect(D_1Bq(v,@zp.9x,$]=#zm+1_2zl+(zo..iK A[i]J)^(0W50?1::vK}jg(i,={x:)*f;Zs!=X#Qext(on ?- 40 zi++";for(Y in $=" #$9@BDGHIJKLNOPQUVWXYZ^_jz")with(_.split($[Y]))_=join(pop());eval(_)
```
135 changes: 135 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@

let cccc = 0;

const getMaxSave = (sourceCode) => {
let arr = sourceCode.split('');//!!!!!!!!!!
let saveArr = [];// as { str: string, count: number, save: number }[];

let f = (n) => {
let dic = Object.create(null);

arr.forEach((v, i) => {
if (i < arr.length - n + 1) {
v = arr.slice(i, i + n).join('');
if (dic[v] == null) dic[v] = 0;
dic[v]++;
}
});

// a | b | c | AAAA

for (let k in dic) {
let count = dic[k];
if (count != 1) {
saveArr.push({
str: k,
count,
save: n * count - count - n - 1//
})
}
}
}

for (let i = 2; i < 32; i++) {//
f(i);
}

saveArr.sort((a, b) => b.save - a.save);
if (saveArr[0] && saveArr[0].save > 0)
return saveArr[0];
else
return null;
}


const getTable = (sourceCode) => {
let table = [];//string[]ƒ
for (let i = 1; i < 128; i++) {
let s = String.fromCharCode(i);
if (
i != 96 &&
i != 10 &&
i != 13 &&
i != 34 &&
i != 39 &&
i != 92 && sourceCode.indexOf(s) == -1) // ` \
table.push(s);
}
return table;
}

function ys(sourceCode) {
let table = getTable(sourceCode);
let tableStr = '';
while (table.length > 0) {
let oneChar = table.pop();
let obj = getMaxSave(sourceCode);
if (obj == null) break;
let s = obj.str;
console.log(`${++cccc} ${s} ${oneChar}`);
tableStr += oneChar;
sourceCode = sourceCode.split(s).join(oneChar) + oneChar + s;
}
tableStr = tableStr.split('').reverse().join('');
let output = '_="' + sourceCode + '";for(Y in $="' + tableStr + '")with(_.split($[Y]))_=join(pop());eval(_)';
return output;
}



let fs = require('fs');


let s = fs.readFileSync('src.js', 'utf-8');

//去单行注释
s = s.replace(/\/\/.*/g, '');

//去空格回车
s = s.replace(/new /g, 'yyyyyyyyyyyyyyy');
s = s.replace(/40px /g, 'zzzzzzzzzzzzzz');

s = s.replace(/[ \r\n]+/g, '');
s = s.replace(/yyyyyyyyyyyyyyy/g, 'new ');
s = s.replace(/zzzzzzzzzzzzzz/g, '40px ');


let ok = 'abdefghklmnopqrstuw'.split('');

let r = (a, b) => s = s.split(a).join(b);


r('状态_左_', -1);
r('状态_上_', -2);
r('状态_右_', -3);

r('状态_开始_', 1);
r('状态_正常_', 2);

r('状态_开始下落_', 3);
r('状态_下落中_', 4);

r('状态_结束下落_', 14);

r('状态_爆炸_', 15);
r('状态_爆炸中_', 16);

r('状态_爆炸结束_', 26);
r('状态_游戏结束_', 27);


//关键词
[
'状态', '结束下落标记', '现在时间', '出现方块x坐标',
'地图',
'动画到', '动画开始位置', '动画结束位置', '动画开始时间',
'是结束', '到xy', '结束',
'渲染', '填充颜色设置', '百分比', '数组', '标记'
].forEach(v => {
s = s.split(v).join(ok.pop());
});


s = ys(s);
fs.writeFileSync('index.js', s);
console.log(s.length);
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd `dirname $0`
node build.js
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

173 changes: 173 additions & 0 deletions src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
c = c.getContext('2d');
c.font = '40px Tahoma';


// const 状态_左_ = -1;
// const 状态_上_ = -2;
// const 状态_右_ = -3;

// const 状态_开始_ = 1;
// const 状态_正常_ = 2;

// const 状态_开始下落_ = 3;
// const 状态_下落中_ = 4;

// const 状态_结束下落_ = 14;//--> top 爆炸 end

// const 状态_爆炸_ = 15;
// const 状态_爆炸中_ = 16;

// const 状态_爆炸结束_ = 26;//--> 开始下落
// const 状态_游戏结束_ = 27;


结束下落标记 = 现在时间 = 0;
出现方块x坐标 = 状态 = 1;
地图 = new Array(54 + 1).fill(0);

填充颜色设置 = (v, n, y, A) => { c.fillStyle = 'hsl(' + v * 35 + ',40%,' + n + '%)' };

动画到 = (v, n, y, A) => {
v.动画开始位置 = { x: v.x, y: v.y };
v.动画结束位置 = { x: n, y };
v.动画开始时间 = 现在时间;
};

结束 = (v, n, y, A) => {
if (!v.是结束) {
v.是结束 = 1;
v.到xy = { y: ~~(n / 6), x: n % 6 };
}
};


onkeydown = (v, n, y, A) => {//事件
v = v.keyCode;
状态 == 状态_正常_ &&
(
状态 = v == 65 && 出现方块x坐标 != 0 ? 状态_左_ :
v == 87 ? 状态_上_ :
v == 68 && 出现方块x坐标 != 3 ? 状态_右_ :
v == 83 ? 状态_开始下落_ : 状态_正常_
)

};

// ontouchmove = (v, n, y, A) => { };
// ontouchstart = (v, n, y, A) => { };
// ontouchend = (v, n, y, A) => { };

渲染 = (v, n, y, A) => { //时间

c.fillStyle = 'rgba(0,0,0,0.2)';
c.fillRect(0, 0, 300, 500);

现在时间++;
数组 = new Array(6).fill(0);
结束下落标记 = 状态_开始_;//
标记 = 1;



地图.forEach(A = (v, n, y, A) => {
x = n % 6;


//左右上
if (n > 47 && 状态 < 0) {
数组[x] = 地图[n];
数组[x + 1] = 地图[n + 1];

//左右
A = 状态 == 状态_左_ ? 1 : 状态 == 状态_右_ ? -1 : 0;

//上
if (状态 == 状态_上_) {
if (标记 && v) {
标记 = 0;
地图[n + 3] = 地图[n];
}
if (v) 数组[x] = 数组[x + 1];
}

地图[n] = v = 数组[x + A];


if (标记 && v) { 标记 = 0; 出现方块x坐标 = x; }
v && 动画到(v, x, 8);
}

//开始
if (状态 == 状态_开始_ &&
n > 47 + 出现方块x坐标 &&
n < 51 + 出现方块x坐标)
动画到(地图[n] = { x, y: 10, i: Math.random() > 0.5 ? 1 : 2, 是结束: 0, 到xy: 0 }, x, 8);


if (v) {

//开始下落
if (状态 == 状态_开始下落_) {
地图[n] = 0;
if (!v.是结束) {
地图[数组[x] * 6 + x] = v;
动画到(v, x, 数组[x]++)
}
}

//爆炸
if (状态 == 状态_爆炸_ && v.是结束 && v.到xy) 动画到(v, v.到xy.x, v.到xy.y);

//爆炸结束
if (状态 == 状态_爆炸结束_ && v.是结束 && !v.到xy) { v.是结束 = 0; v.i++ }

//结束下落
if (状态 == 状态_结束下落_) {
for (i = 0; i < (x == 0 || x == 5 ? 1 : 4); i++) {
A = [6, 1, 7, - 5];
a = 地图[n + A[i]];
b = 地图[n - A[i]];
if (a && b && a.i == v.i && b.i == v.i) {
v.是结束 = 1;
v.到xy = 0;
结束(a, n);
结束(b, n);
结束下落标记 = 状态_爆炸_;
}
}
if (n > 47 && 结束下落标记 != 状态_爆炸_) {
结束下落标记 = 状态_游戏结束_
}
}

//draw
if (!(n > 47 && 状态 == 状态_游戏结束_ && 现在时间 % 40 > 20)) {
//动画步
百分比 = (现在时间 - v.动画开始时间) / 10;
if (百分比 > 1) 百分比 = 1;
v.x = v.动画开始位置.x + (v.动画结束位置.x - v.动画开始位置.x) * 百分比;
v.y = v.动画开始位置.y + (v.动画结束位置.y - v.动画开始位置.y) * 百分比;

//draw
x = 50 * v.x;
y = 450 - 50 * v.y;
i = v.i;

填充颜色设置(i, 65);
c.fillRect(x, y, 50, 50);

填充颜色设置(i, 20);
c.fillText(v.i, x + 12, y + 40)
}

}
});

状态 = 状态 < 0 ? 状态_正常_ :
状态 == 状态_正常_ || 状态 == 状态_游戏结束_ ? 状态 :
状态 == 状态_结束下落_ ? 结束下落标记 :
状态 == 状态_爆炸结束_ ? 状态_开始下落_ : 状态 + 1;

requestAnimationFrame(渲染)
};
渲染()

0 comments on commit c1522fe

Please sign in to comment.