Class: Character

Inherits:
Object
  • Object
show all
Defined in:
lib/characters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#agilityObject

Returns the value of attribute agility.



6
7
8
# File 'lib/characters.rb', line 6

def agility
  @agility
end

#armourObject

Returns the value of attribute armour.



6
7
8
# File 'lib/characters.rb', line 6

def armour
  @armour
end

#enduranceObject

Returns the value of attribute endurance.



6
7
8
# File 'lib/characters.rb', line 6

def endurance
  @endurance
end

#experienceObject

Returns the value of attribute experience.



6
7
8
# File 'lib/characters.rb', line 6

def experience
  @experience
end

#intelligenceObject

Returns the value of attribute intelligence.



6
7
8
# File 'lib/characters.rb', line 6

def intelligence
  @intelligence
end

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/characters.rb', line 6

def level
  @level
end

#lifeObject

Returns the value of attribute life.



6
7
8
# File 'lib/characters.rb', line 6

def life
  @life
end

#magicObject

Returns the value of attribute magic.



6
7
8
# File 'lib/characters.rb', line 6

def magic
  @magic
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/characters.rb', line 6

def name
  @name
end

#spellsObject

Returns the value of attribute spells.



6
7
8
# File 'lib/characters.rb', line 6

def spells
  @spells
end

#strengthObject

Returns the value of attribute strength.



6
7
8
# File 'lib/characters.rb', line 6

def strength
  @strength
end

#weaponObject

Returns the value of attribute weapon.



6
7
8
# File 'lib/characters.rb', line 6

def weapon
  @weapon
end

Instance Method Details

#armour_ratingObject



23
24
25
26
27
28
29
# File 'lib/characters.rb', line 23

def armour_rating
	initial_rating = 0
	self.armour.each do |armour|
		initial_rating += (armour.rating)
	end
	return initial_rating
end

#attributeObject



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

#statsObject



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