本文整理汇总了TypeScript中Imports/Core/Arrays.Array2D类的典型用法代码示例。如果您正苦于以下问题:TypeScript Array2D类的具体用法?TypeScript Array2D怎么用?TypeScript Array2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Array2D类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Array2D
QUnit.test(name("Birth wins when dead"), assert => {
const t = GameOfLifeTransformer.create([3], [3]);
const nextWorld = new Array2D(3, 3, false);
const w = getWorld(3, 1, 1);
t.transform(w, nextWorld);
assert.strictEqual(nextWorld.get(1, 1), true);
});
示例2: 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;
}
示例3: render
render(world: Array2D<T>) {
checkDefinedAndNotNull("world", world);
this.context.clearRect(0, 0,
world.width * this.pointSize, world.height * this.pointSize);
for (let row = 0; row < world.height; row++) {
for (let column = 0; column < world.width; column++) {
if (world.get(row, column)) {
this.context.fillRect(column * this.pointSize, row * this.pointSize,
this.pointSize, this.pointSize);
}
}
}
}
示例4: 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);
}