[verified] Snake 0.8: circular arena and larger 32px tiles
This commit is contained in:
+9
-9
@@ -7,13 +7,13 @@ const snake = require('../src/common/snake.js');
|
||||
const ux = fs.readFileSync('src/pages/index/index.ux', 'utf8');
|
||||
const body = ux.match(/<script>([\s\S]*?)<\/script>/)[1]
|
||||
.replace(/import\s+\w+\s+from\s+'[^']*';?/g, '')
|
||||
.replace(/^const\s+\w+\s*=[^\n]*\n/gm, '')
|
||||
.replace('export default', '');
|
||||
.replace('export default', 'globalThis.spec =');
|
||||
|
||||
const sandbox = { best: require('../src/common/best.js'), storage: {get() {}, set() {}}, snake, Date, Math, String, Number, console, setInterval: () => 0, clearInterval: () => {},
|
||||
CELL: 20, GRID: 16, OFFSET: 73 };
|
||||
};
|
||||
vm.createContext(sandbox);
|
||||
const spec = vm.runInContext('(' + body + ')', sandbox);
|
||||
vm.runInContext(body, sandbox);
|
||||
const spec = sandbox.spec;
|
||||
|
||||
function mk() {
|
||||
const o = Object.assign({}, spec, JSON.parse(JSON.stringify(spec.private)));
|
||||
@@ -29,10 +29,10 @@ assert.match(c.snake[0].src, /head_e\.png$/, 'head texture');
|
||||
assert.match(c.snake[1].src, /body_h\.png$/, 'body texture');
|
||||
assert.match(c.snake[2].src, /tail_w\.png$/, 'tail texture');
|
||||
assert.equal(c.scoreText, 'SCORE 0');
|
||||
assert.equal(c.snake[0].left, (73 + 6 * 20) + 'px', 'head x mapped to px');
|
||||
assert.equal(c.snake[0].left, (snake.ARENA.offset + 6 * snake.ARENA.cell) + 'px', 'head x mapped to px');
|
||||
|
||||
for (let i = 0; i < 5; i++) c.tick();
|
||||
assert.equal(c.model[0].x, 11, 'head moved right 5 steps from x=6');
|
||||
for (let i = 0; i < 1; i++) c.tick();
|
||||
assert.equal(c.model[0].x, 7, 'head moved right one step from x=6');
|
||||
assert.equal(c.over, false);
|
||||
|
||||
c.onSwipe({ direction: 'down' });
|
||||
@@ -47,8 +47,8 @@ c.tick();
|
||||
assert.equal(c.dir.x, 0, 'reversal keeps x');
|
||||
assert.equal(c.dir.y, 1, 'reversal blocked');
|
||||
|
||||
// run into the wall to trigger game over (GRID=16, last column x=15)
|
||||
c.model = [{ x: 15, y: 5 }, { x: 14, y: 5 }, { x: 13, y: 5 }];
|
||||
// Hit the actual circular boundary.
|
||||
c.model = [{ x: 10, y: 5 }, { x: 9, y: 5 }, { x: 8, y: 5 }];
|
||||
c.dir = { x: 1, y: 0 };
|
||||
c.pending = null;
|
||||
c.tick();
|
||||
|
||||
Reference in New Issue
Block a user