Class: Character
- Inherits:
-
Object
- Object
- Character
- Defined in:
- lib/characters.rb
Instance Attribute Summary collapse
-
#agility ⇒ Object
Returns the value of attribute agility.
-
#armour ⇒ Object
Returns the value of attribute armour.
-
#endurance ⇒ Object
Returns the value of attribute endurance.
-
#experience ⇒ Object
Returns the value of attribute experience.
-
#intelligence ⇒ Object
Returns the value of attribute intelligence.
-
#level ⇒ Object
Returns the value of attribute level.
-
#life ⇒ Object
Returns the value of attribute life.
-
#magic ⇒ Object
Returns the value of attribute magic.
-
#name ⇒ Object
Returns the value of attribute name.
-
#spells ⇒ Object
Returns the value of attribute spells.
-
#strength ⇒ Object
Returns the value of attribute strength.
-
#weapon ⇒ Object
Returns the value of attribute weapon.
Instance Method Summary collapse
- #armour_rating ⇒ Object
- #attribute ⇒ Object
-
#initialize(name, strength, endurance, agility, intelligence, level, experience, weapon = '', headgear = None, feet = None, hands = None, shield = None, armour = None) ⇒ Character
constructor
A new instance of Character.
- #stats ⇒ Object
Constructor Details
#initialize(name, strength, endurance, agility, intelligence, level, experience, weapon = '', headgear = None, feet = None, hands = None, shield = None, armour = None) ⇒ Character
Returns a new instance of Character.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/characters.rb', line 8 def initialize(name, strength, endurance, agility, intelligence, level, experience, weapon = '', headgear = None, feet =None, hands = None, shield = None, armour = None) @name = name @strength = strength @endurance = endurance @agility = agility @intelligence = intelligence @level = level @experience = experience @life = endurance * 10 @magic = intelligence * 3 @spells = ['heal'] @armour = [headgear, feet, hands, shield, armour] @weapon = [weapon] end |
Instance Attribute Details
#agility ⇒ Object
Returns the value of attribute agility.
6 7 8 |
# File 'lib/characters.rb', line 6 def agility @agility end |
#armour ⇒ Object
Returns the value of attribute armour.
6 7 8 |
# File 'lib/characters.rb', line 6 def armour @armour end |
#endurance ⇒ Object
Returns the value of attribute endurance.
6 7 8 |
# File 'lib/characters.rb', line 6 def endurance @endurance end |
#experience ⇒ Object
Returns the value of attribute experience.
6 7 8 |
# File 'lib/characters.rb', line 6 def experience @experience end |
#intelligence ⇒ Object
Returns the value of attribute intelligence.
6 7 8 |
# File 'lib/characters.rb', line 6 def intelligence @intelligence end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/characters.rb', line 6 def level @level end |
#life ⇒ Object
Returns the value of attribute life.
6 7 8 |
# File 'lib/characters.rb', line 6 def life @life end |
#magic ⇒ Object
Returns the value of attribute magic.
6 7 8 |
# File 'lib/characters.rb', line 6 def magic @magic end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/characters.rb', line 6 def name @name end |
#spells ⇒ Object
Returns the value of attribute spells.
6 7 8 |
# File 'lib/characters.rb', line 6 def spells @spells end |
#strength ⇒ Object
Returns the value of attribute strength.
6 7 8 |
# File 'lib/characters.rb', line 6 def strength @strength end |
#weapon ⇒ Object
Returns the value of attribute weapon.
6 7 8 |
# File 'lib/characters.rb', line 6 def weapon @weapon end |
Instance Method Details
#armour_rating ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/characters.rb', line 23 def = 0 self.armour.each do |armour| += (armour.) end return end |
#attribute ⇒ Object
31 32 33 34 35 |
# File 'lib/characters.rb', line 31 def attribute {:strength => strength, :endurance => endurance, :agility => agility, :intelligence => intelligence}.each do |attribute, value| puts attribute.to_s.capitalize + ': ' + value.to_s end end |
#stats ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/characters.rb', line 37 def stats puts '='*10 self.attribute puts '' puts "Level: #{self.level.to_s}" puts "Health: #{self.life.to_s} / #{(self.endurance*10).to_s}" puts "Magic: #{self.magic.to_s} / #{(self.intelligence*3).to_s}" puts "Current experience: #{self.experience.to_s}" puts "Exp. until next level: #{((50 *self.level * self.level) - (self.experience)).to_s}" puts '' end |