| 1 | 'use strict'; |
| 2 | |
| 3 | const { describe, it } = require('node:test'); |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const { makeGame, placeRow, GameCore, Planet } = require('./helpers.js'); |
| 6 | |
| 7 | describe('Points, landing and recolor', () => |
| 8 | { |
| 9 | it('blocks that leave the top of the field become one point each and are gone', () => |
| 10 | { |
| 11 | const g = makeGame({ |
| 12 | noSpawn: true, |
| 13 | planetOpts: { jumpsToClear: 1, fallTime: 5, riseTime: 0.5 } |
| 14 | }); |
| 15 | placeRow(g, 0, [0, 1, 2], 0); |
| 16 | const carried = g.place(1, 1, 4); |
| 17 | g.resolveMatches(); |
| 18 | assert.equal(g.score, 0); |
| 19 | g.step(2, 1 / 120); |
| 20 | assert.equal(g.blocks.filter((b) => b.state === 'flying').length, 0); |
| 21 | assert.equal(g.score, 4, '3 rockets + 1 carried'); |
| 22 | assert.equal(g.blockAt(1, 1), null); |
| 23 | assert.ok(!g.blocks.includes(carried) && carried.y >= g.height || g.score === 4); |
| 24 | }); |
| 25 | |
| 26 | it('a cluster that does not clear the field lands, sits for 3 seconds, then takes random colors', () => |
| 27 | { |
| 28 | const g = makeGame({ |
| 29 | noSpawn: true, |
| 30 | planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 }, |
| 31 | seed: 99 |
| 32 | }); |
| 33 | placeRow(g, 0, [3, 4, 5], 2); |
| 34 | g.resolveMatches(); |
| 35 | // Jump height is 13/4 = 3.25, they come back down. Step until they land. |
| 36 | let landed = false; |
| 37 | for (let i = 0; i < 2000; i++) |
| 38 | { |
| 39 | g.tick(1 / 120); |
| 40 | const grayNow = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY); |
| 41 | if (grayNow.length >= 3 && grayNow.every((b) => b.state === 'settling')) |
| 42 | { |
| 43 | landed = true; |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | const gray = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY); |
| 48 | assert.ok(landed, 'should have landed as gray, got ' + gray.length + ' states=' + gray.map((b) => b.state + '@' + b.y).join(',') + '\n' + g.snapshot().picture); |
| 49 | for (const b of gray) |
| 50 | { |
| 51 | assert.equal(b.state, 'settling'); |
| 52 | assert.ok(b.y < 6, 'landed low, y=' + b.y); |
| 53 | assert.ok(b.settleTime < 0.05, 'timer starts at landing, t=' + b.settleTime); |
| 54 | } |
| 55 | g.step(2.9, 1 / 60); |
| 56 | assert.ok(gray.every((b) => b.state === 'settling'), 'still settling just before 3s: ' + gray.map((b) => b.state + '/' + b.settleTime).join(',')); |
| 57 | g.step(0.2, 1 / 60); |
| 58 | for (const b of gray) |
| 59 | { |
| 60 | assert.equal(b.state, 'still'); |
| 61 | assert.ok(b.color >= 0 && b.color < 5, 'recolored, color=' + b.color); |
| 62 | assert.equal(b.clusterId, null); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | it('carried colored blocks land as still blocks and do not wait 3 seconds', () => |
| 67 | { |
| 68 | const g = makeGame({ |
| 69 | noSpawn: true, |
| 70 | planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } |
| 71 | }); |
| 72 | placeRow(g, 0, [0, 1, 2], 0); |
| 73 | const carried = g.place(1, 1, 4); |
| 74 | g.resolveMatches(); |
| 75 | g.step(4, 1 / 120); |
| 76 | assert.equal(carried.color, 4); |
| 77 | assert.equal(carried.state, 'still'); |
| 78 | assert.equal(carried.clusterId, null); |
| 79 | }); |
| 80 | |
| 81 | it('spawn drops a random color into a random open column every second', () => |
| 82 | { |
| 83 | const g = makeGame({ seed: 3 }); |
| 84 | assert.equal(g.blocks.length, 0); |
| 85 | g.step(0.99); |
| 86 | assert.equal(g.blocks.length, 0); |
| 87 | g.step(0.02); |
| 88 | assert.equal(g.blocks.length, 1); |
| 89 | assert.equal(g.blocks[0].state, 'falling'); |
| 90 | assert.ok(g.blocks[0].color >= 0 && g.blocks[0].color < 5); |
| 91 | assert.ok(g.blocks[0].col >= 0 && g.blocks[0].col < 10); |
| 92 | g.step(1); |
| 93 | assert.equal(g.blocks.length, 2); |
| 94 | // Let the first one land. |
| 95 | g.step(g.planet.fallTime + 0.2); |
| 96 | const landed = g.blocks.filter((b) => b.state === 'still'); |
| 97 | assert.ok(landed.length >= 1); |
| 98 | for (const b of landed) |
| 99 | { assert.equal(b.y, 0); } |
| 100 | }); |
| 101 | }); |
projects-timfalken-com meteors