Class: CharacterBuilder
- Inherits:
-
Object
- Object
- CharacterBuilder
- Defined in:
- lib/D_D_Character_Gen.rb
Instance Attribute Summary collapse
- #age ⇒ Object
- #gender ⇒ Object
-
#name ⇒ Object
writeonly
Sets the attribute name.
- #p_class ⇒ Object
- #race ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ CharacterBuilder
constructor
A new instance of CharacterBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CharacterBuilder
Returns a new instance of CharacterBuilder.
3 4 5 6 7 8 9 |
# File 'lib/D_D_Character_Gen.rb', line 3 def initialize p_class race gender age name end |
Instance Attribute Details
#age ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/D_D_Character_Gen.rb', line 27 def age if @race=="elf" then @age=(rand(15..150)) elsif @race=="human" then @age=(rand(15..50)) elsif @race=="wizard" then @age=(rand(15..130)) elsif @race=="gnome" then @age=(rand(15..130)) elsif @race=="dwarf" then @age=(rand(15..90)) elsif @race=="halfling" then @age=(rand(15..100)) elsif @race=="half-orc" then @age=(rand(15..120)) end end |
#gender ⇒ Object
13 14 15 |
# File 'lib/D_D_Character_Gen.rb', line 13 def gender @gender=["male","female"].sample end |
#name=(value) ⇒ Object (writeonly)
Sets the attribute name
2 3 4 |
# File 'lib/D_D_Character_Gen.rb', line 2 def name=(value) @name = value end |
#p_class ⇒ Object
10 11 12 |
# File 'lib/D_D_Character_Gen.rb', line 10 def p_class @p_class=["rogue", "wizard", "fighter", "cleric"].sample end |
#race ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/D_D_Character_Gen.rb', line 16 def race if @p_class=="fighter" then @race=["dwarf", "human","gnome"].sample elsif @p_class=="wizard" then @race=["halfling", "elf","human"].sample elsif @p_class=="cleric" then @race=["elf", "halfling","half-orc"].sample elsif @p_class=="rogue" then @race=["elf", "half-orc","human"].sample end end |
Instance Method Details
#to_s ⇒ Object
44 45 46 |
# File 'lib/D_D_Character_Gen.rb', line 44 def to_s "Hello #{@name}: You are a #{@gender} #{@race} #{@p_class}, aged #{@age}. \n" end |