本文整理匯總了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);
}