Browse Source

Remove unnecessary constructor(), add print line

tags/v0.1.3
bertieb 3 years ago
parent
commit
fd42ead81b
1 changed files with 10 additions and 11 deletions
  1. +10
    -11
      dice.ts

+ 10
- 11
dice.ts View File

@@ -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…
Cancel
Save