Class: Brawl::BasicArenaObject

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

Direct Known Subclasses

BasicBot, Wall

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BasicArenaObject

Returns a new instance of BasicArenaObject.



10
11
12
13
14
15
16
17
18
19
# File 'lib/brawl/basic_arena_object.rb', line 10

def initialize(params={})
  @clock      = params[:clock]
  @id         = params[:id] || UUIDTools::UUID.timestamp_create.to_s
  @name       = params[:name] || self.object_id
  @location   = params[:location] || {x: 0, y: 0}
  @heading    = params[:heading] || 0
  @health     = params[:health] || 1
  @properties = params[:properties] || 
    [:id, :name, :class, :location, :health, :heading]
end

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



7
8
9
# File 'lib/brawl/basic_arena_object.rb', line 7

def clock
  @clock
end

#headingObject

Returns the value of attribute heading.



8
9
10
# File 'lib/brawl/basic_arena_object.rb', line 8

def heading
  @heading
end

#healthObject

Returns the value of attribute health.



8
9
10
# File 'lib/brawl/basic_arena_object.rb', line 8

def health
  @health
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/brawl/basic_arena_object.rb', line 7

def id
  @id
end

#locationObject

Returns the value of attribute location.



8
9
10
# File 'lib/brawl/basic_arena_object.rb', line 8

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/brawl/basic_arena_object.rb', line 7

def name
  @name
end

Instance Method Details

#damage(damage_points) ⇒ Object



28
29
30
31
# File 'lib/brawl/basic_arena_object.rb', line 28

def damage(damage_points)
  @health -= damage_points
  @health < 0 ? @health = 0 : @health
end

#propertiesObject

properties are values that are OK to be publicly ‘seen’ in the arena



22
23
24
25
26
# File 'lib/brawl/basic_arena_object.rb', line 22

def properties
  @properties.each_with_object({}) do |property, hash|
    hash[property] = self.send(property)
  end
end