diff --git a/exercises/practice/dnd-character/.meta/config.json b/exercises/practice/dnd-character/.meta/config.json index dd16150b2d..092784b0c0 100644 --- a/exercises/practice/dnd-character/.meta/config.json +++ b/exercises/practice/dnd-character/.meta/config.json @@ -1,5 +1,8 @@ { - "authors": [], + "authors": [ + "mr-sigma", + "kotp" + ], "files": { "solution": [ "dnd_character.rb" diff --git a/exercises/practice/dnd-character/.meta/example.rb b/exercises/practice/dnd-character/.meta/example.rb index e69de29bb2..57cd1aea32 100644 --- a/exercises/practice/dnd-character/.meta/example.rb +++ b/exercises/practice/dnd-character/.meta/example.rb @@ -0,0 +1,53 @@ +module Die + extend self + + def roll(roll: 4, die: 6, remove_lowest: 1) + roll.times.map { rand(1..die) }.sort.pop(roll - remove_lowest).sum + end + +end + +module Modifiable + + # This only calculates hit point modifier based on constitution + def modifier(constitution) + constitution/2 - 5 + end + +end + +class DndCharacter + extend Modifiable + + BASE_HITPOINTS = 10 + + private_constant :BASE_HITPOINTS + + private + + def initialize + @strength = Die.roll + @dexterity = Die.roll + @constitution = Die.roll + @intelligence = Die.roll + @wisdom = Die.roll + @charisma = Die.roll + + @hitpoints = BASE_HITPOINTS + self.class.modifier(constitution) + end + + public + + attr_reader :strength, + :dexterity, + :constitution, + :intelligence, + :wisdom, + :charisma, + :hitpoints + +end + +if $PROGRAM_NAME == __FILE__ + puts DndCharacter.allocate.public_methods(false) +end