class Patterns::Monster

Monster -> Object

The monster class. It delegates its calls to the monster type class. This is an example of the Type Object pattern. This is also an example of the concept of Object Composition over inheritance. The monster HAS a type attribute instead of inheriting one. This allows us to decouple the monster from its type and stops inheritance from getting out of control in a system with many similar objects.

Attributes

monster_type[RW]

The MonsterType object of the Monster

Public Class Methods

new(monster_type) click to toggle source

Initializes the monster class

  • monster_type - The type of the monster that has a corresponding json file

Examples

=> orc = Monster.new('orc')
# File app/models/type_object/monster.rb, line 21
def initialize(monster_type)
  @monster_type = MonsterType.new(monster_type)
end

Public Instance Methods

attack() click to toggle source

Delegates getting monster attack to the #monster_type

Examples

=> orc.attack
# File app/models/type_object/monster.rb, line 48
def attack
  @monster_type.attack
end
deep_clone() click to toggle source

Performs a deep clone of the Monster Object by utilizing the MonsterType object

Examples

=> orc2 = orc.clone
# File app/models/type_object/monster.rb, line 30
def deep_clone
  Monster.new(@monster_type)
end
health() click to toggle source

Delegates getting monster health to the #monster_type

Examples

=> orc.health
# File app/models/type_object/monster.rb, line 39
def health
  @monster_type.health
end
prototype_name() click to toggle source

Gets this monster's prototype name if it has one and the string 'none' if it does not

Examples

=> orc_wizard.prototype_name
# File app/models/type_object/monster.rb, line 84
def prototype_name
  @monster_type.prototype_name
end
range() click to toggle source

Delegates getting monster range to the #monster_type

Examples

=> orc.range
# File app/models/type_object/monster.rb, line 57
def range
  @monster_type.range
end
resistances() click to toggle source

Delegates getting monster resistances to the #monster_type

Examples

=> orc.resistances
# File app/models/type_object/monster.rb, line 66
def resistances
  @monster_type.resistances
end
weaknesses() click to toggle source

Delegates getting monster weaknesses to the #monster_type

Examples

=> orc.weaknesses
# File app/models/type_object/monster.rb, line 75
def weaknesses
  @monster_type.weaknesses
end