'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, fillColumn, GameCore } = require('./helpers.js'); describe('Column lock and game over', () => { it('a column filled from floor to top becomes dark gray and locked', () => { const g = makeGame({ noSpawn: true }); fillColumn(g, 3, 13, [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2]); g.checkLocks(); assert.equal(g.isColumnLocked(3), true); assert.equal(g.isColumnStill(3), false); for (let r = 0; r < 13; r++) { const b = g.blockAt(3, r); assert.ok(b); assert.equal(b.state, 'locked'); assert.equal(b.color, GameCore.COLOR_GRAY); } assert.equal(g.beginDrag(3, 5), false); }); it('a new spawn never lands in a locked column', () => { const g = makeGame({ seed: 11, noSpawn: false }); g.spawnInterval = 1e9; fillColumn(g, 0, 13, [0, 1]); g.checkLocks(); assert.equal(g.isColumnLocked(0), true); for (let i = 0; i < 40; i++) { const spawned = g.trySpawn(); assert.ok(spawned); assert.notEqual(spawned.col, 0); g.removeBlock(spawned); } }); it('a nearly full column (12 blocks) is not locked', () => { const g = makeGame({ noSpawn: true }); fillColumn(g, 2, 12, [0, 1, 2]); g.checkLocks(); assert.equal(g.isColumnLocked(2), false); assert.equal(g.isColumnStill(2), true); assert.ok(g.beginDrag(2, 0)); g.endDrag(); }); it('when every column is locked the player loses', () => { const g = makeGame({ noSpawn: true }); for (let c = 0; c < 10; c++) { fillColumn(g, c, 13, [c % 5, (c + 1) % 5, (c + 2) % 5]); } g.tick(0.01); assert.equal(g.state, 'gameover'); assert.equal(g.lockedColumnCount(), 10); assert.equal(g.trySpawn(), null); assert.equal(g.beginDrag(0, 0), false); }); it('game over does not fire while at least one column is open', () => { const g = makeGame({ noSpawn: true }); for (let c = 0; c < 9; c++) { fillColumn(g, c, 13, [0, 1, 2]); } fillColumn(g, 9, 4, [3, 4]); g.checkLocks(); g.checkGameOver(); assert.equal(g.state, 'playing'); assert.equal(g.lockedColumnCount(), 9); }); });