| 1 | 'use strict'; |
| 2 | |
| 3 | const Planet = require('../src/planet.js'); |
| 4 | const Rng = require('../src/rng.js'); |
| 5 | const { GameCore } = require('../src/gameCore.js'); |
| 6 | |
| 7 | function makeGame (opts) |
| 8 | { |
| 9 | opts = opts || {}; |
| 10 | const planet = opts.planet || Planet.createPlanet(opts.planetOpts || { |
| 11 | jumpsToClear: 2, |
| 12 | fallTime: 3, |
| 13 | riseTime: 1.5 |
| 14 | }); |
| 15 | const rng = typeof opts.seed === 'number' ? Rng.create(opts.seed) : (opts.rng || Rng.create(1)); |
| 16 | const game = new GameCore(planet, rng); |
| 17 | if (opts.noSpawn) |
| 18 | { game.spawnInterval = 1e9; } |
| 19 | if (opts.strictInvariants !== false) |
| 20 | { game.strictInvariants = true; } |
| 21 | return game; |
| 22 | } |
| 23 | |
| 24 | /** Fill a column with `count` still blocks of rotating colors starting at 0. */ |
| 25 | function fillColumn (game, col, count, colors) |
| 26 | { |
| 27 | colors = colors || [0, 1, 2, 3, 4]; |
| 28 | const out = []; |
| 29 | for (let r = 0; r < count; r++) |
| 30 | { out.push(game.place(col, r, colors[r % colors.length])); } |
| 31 | return out; |
| 32 | } |
| 33 | |
| 34 | function placeRow (game, row, cols, color) |
| 35 | { |
| 36 | const out = []; |
| 37 | for (const c of cols) |
| 38 | { out.push(game.place(c, row, color)); } |
| 39 | return out; |
| 40 | } |
| 41 | |
| 42 | function grayFlying (game) |
| 43 | { |
| 44 | return game.blocks.filter((b) => b.state === 'flying' && b.color === GameCore.COLOR_GRAY); |
| 45 | } |
| 46 | |
| 47 | function almost (a, b, eps) |
| 48 | { |
| 49 | eps = eps == null ? 1e-6 : eps; |
| 50 | return Math.abs(a - b) <= eps; |
| 51 | } |
| 52 | |
| 53 | module.exports = { |
| 54 | makeGame, |
| 55 | fillColumn, |
| 56 | placeRow, |
| 57 | grayFlying, |
| 58 | almost, |
| 59 | Planet, |
| 60 | Rng, |
| 61 | GameCore |
| 62 | }; |
projects-timfalken-com meteors