diff --git a/dice.ts b/dice.ts index 9cfb810..d0f9c31 100644 --- a/dice.ts +++ b/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)); }