瀏覽代碼

Remove unnecessary constructor(), add print line

tags/v0.1.3
bertieb 3 年之前
父節點
當前提交
fd42ead81b
共有 1 個檔案被更改,包括 10 行新增11 行删除
  1. +10
    -11
      dice.ts

+ 10
- 11
dice.ts 查看文件

@@ -51,7 +51,15 @@ class D10 implements Dice {
sides: number = 10;
type: string = "d10"

constructor() {
roll(numberToRoll: number): DiceResult {
let results: DiceResult = { total: 0, dice: [] };
for (let i = 0; i < numberToRoll; i++) {
results.dice.push(randIntMinOne(this.sides));
}

results.total = results.dice.reduce((acc: number, curr: number) => acc + curr);

return results;
}

[util.inspect.custom](): string {
@@ -71,16 +79,6 @@ class D10 implements Dice {
* { total: 16, dice [ 3, 5, 6, 2] }
*
*/
roll(numberToRoll: number): DiceResult {
let results: DiceResult = { total: 0, dice: [] };
for (let i = 0; i < numberToRoll; i++) {
results.dice.push(randIntMinOne(this.sides));
}

results.total = results.dice.reduce((acc: number, curr: number) => acc + curr);

return results;
}
}

class Asphodice extends D10 {
@@ -292,6 +290,7 @@ class Asphodice extends D10 {
let asphodice: Asphodice = new Asphodice();
let number: number = 4;
for (let i = 0; i < 10; i++) {
console.log("--------------------");
console.log("Rolling", number, asphodice);
console.log(asphodice.roll(4));
}

Loading…
取消
儲存