|
@@ -51,7 +51,15 @@ class D10 implements Dice { |
|
|
sides: number = 10; |
|
|
sides: number = 10; |
|
|
type: string = "d10" |
|
|
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 { |
|
|
[util.inspect.custom](): string { |
|
@@ -71,16 +79,6 @@ class D10 implements Dice { |
|
|
* { total: 16, dice [ 3, 5, 6, 2] } |
|
|
* { 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 { |
|
|
class Asphodice extends D10 { |
|
@@ -292,6 +290,7 @@ class Asphodice extends D10 { |
|
|
let asphodice: Asphodice = new Asphodice(); |
|
|
let asphodice: Asphodice = new Asphodice(); |
|
|
let number: number = 4; |
|
|
let number: number = 4; |
|
|
for (let i = 0; i < 10; i++) { |
|
|
for (let i = 0; i < 10; i++) { |
|
|
|
|
|
console.log("--------------------"); |
|
|
console.log("Rolling", number, asphodice); |
|
|
console.log("Rolling", number, asphodice); |
|
|
console.log(asphodice.roll(4)); |
|
|
console.log(asphodice.roll(4)); |
|
|
} |
|
|
} |