当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Array2D.set方法代码示例

本文整理汇总了TypeScript中Imports/Core/Arrays.Array2D.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Array2D.set方法的具体用法?TypeScript Array2D.set怎么用?TypeScript Array2D.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imports/Core/Arrays.Array2D的用法示例。


在下文中一共展示了Array2D.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Array2D

QUnit.test(name("Overlapping death"), assert => {
    const t = GameOfLifeTransformer.create([1], []);
    const w = new Array2D(3, 4, false);
    const nextWorld = new Array2D(3, 4, false);
    w.set(1, 2, true);
    w.set(1, 3, true);

    t.transform(w, nextWorld);

    assert.strictEqual(nextWorld.get(0, 0), false);
    assert.strictEqual(nextWorld.get(0, 1), false);
});
开发者ID:cfuehrmann,项目名称:GameOfLife,代码行数:12,代码来源:GameOfLifeTransformer_test.ts

示例2: checkInt

 fillRect: (x, y, w, h) => {
     checkInt("x", x);
     checkInt("y", y);
     assert.ok(x >= 0);
     assert.ok(y >= 0);
     assert.strictEqual(w, pointSize);
     assert.strictEqual(h, pointSize);
     const row = Math.floor(y / pointSize);
     const column = Math.floor(x / pointSize);
     assert.ok(world.get(row, column));
     world.set(row, column, false);
 }
开发者ID:cfuehrmann,项目名称:GameOfLife,代码行数:12,代码来源:RectRenderer_test.ts

示例3: getWorld

function getWorld(n: number, sparedRow: number, sparedCol: number) {
    const result = new Array2D(3, 3, false);

    let numberOfPointsSet = 0;

    for (let row = 0; row < 3; row++) {
        for (let col = 0; col < 3; col++) {

            if (numberOfPointsSet >= n) {
                return result;
            }

            if (row !== sparedRow || col !== sparedCol) {
                result.set(row, col, true);
                numberOfPointsSet++;
            }
        }
    }

    return result;
}
开发者ID:cfuehrmann,项目名称:GameOfLife,代码行数:21,代码来源:GameOfLifeTransformer_test.ts

示例4: Array2D

canvasElement.width = width * pointSize;
canvasElement.height = height * pointSize;

const ctx = canvasElement.getContext("2d")!;

ctx.fillStyle = `rgb(${String(0)}, ${String(0)}, ${String(0)})`;

document.getElementById("content")!.appendChild(canvasElement);

const renderer = RectRenderer.create(ctx, pointSize);

let currentWorld = new Array2D(height, width, false);
let nextWorld = new Array2D(height, width, false);

for (let row = 0; row < height; row++) {
    for (let column = 0; column < width; column++) {
        currentWorld.set(row, column, Math.random() < 0.5001);
    }
}

const transformer = GameOfLifeTransformer.create(survival, birth);

setInterval(() => {
    renderer.render(currentWorld);

    transformer.transform(currentWorld, nextWorld);

    const h = currentWorld;
    currentWorld = nextWorld;
    nextWorld = h;
}, 50);
开发者ID:cfuehrmann,项目名称:GameOfLife,代码行数:31,代码来源:World.ts

示例5: TestContext

QUnit.test(name("ContextCallSequence"), assert => {
    // PREPARE

    const context = new TestContext();
    const pointSize = 4;
    const renderer = RectRenderer.create(context, pointSize);
    const width = 5;
    const height = 3;
    const world = new Array2D(height, width, false);

    world.set(0, 0, true);
    world.set(0, 1, false);
    world.set(0, 2, true);
    world.set(0, 3, false);
    world.set(0, 4, true);

    world.set(1, 0, false);
    world.set(1, 1, true);
    world.set(1, 2, false);
    world.set(1, 3, true);
    world.set(1, 4, false);

    world.set(2, 0, true);
    world.set(2, 1, false);
    world.set(2, 2, true);
    world.set(2, 3, false);
    world.set(2, 4, true);

    // ACT

    renderer.render(world);

    // ASSERT 

    // The first call must be clearRect with the proper parameters:
    assert.ok(context.calls[0].match({
        clearRect: (x, y, w, h) => x === 0 && y === 0 &&
            w === width * pointSize && h === height * pointSize,
        fillRect: () => false
    }));

    // The subsequent calls must be fillRects with proper parameters.
    // In particular, each fillRect call must correspond to coordinates
    // where "world" is true, and no such coordinates must occur twice:
    for (let i = 1; i < context.calls.length; i++) {
        context.calls[i].match({
            clearRect: () => assert.ok(false),
            fillRect: (x, y, w, h) => {
                checkInt("x", x);
                checkInt("y", y);
                assert.ok(x >= 0);
                assert.ok(y >= 0);
                assert.strictEqual(w, pointSize);
                assert.strictEqual(h, pointSize);
                const row = Math.floor(y / pointSize);
                const column = Math.floor(x / pointSize);
                assert.ok(world.get(row, column));
                world.set(row, column, false);
            }
        });
    }

    // The calls to fillRect must exhaust all coordinates where world is true:
    for (let row = 0; row < height; row++) {
        for (let column = 0; column < width; column++) {
            assert.strictEqual(world.get(row, column), false);
        }
    }
});
开发者ID:cfuehrmann,项目名称:GameOfLife,代码行数:69,代码来源:RectRenderer_test.ts


注:本文中的Imports/Core/Arrays.Array2D.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。