Class: Hearthstone::Models::Entity
- Inherits:
-
Object
- Object
- Hearthstone::Models::Entity
- Defined in:
- lib/hearthstone/models/entity.rb
Overview
represent an object in game
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#card ⇒ Object
Returns the value of attribute card.
-
#damaged ⇒ Object
Returns the value of attribute damaged.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #attach(card) ⇒ Object
- #attack ⇒ Object
- #current_health ⇒ Object
- #detach(card) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(id: nil, card: nil) ⇒ Entity
constructor
A new instance of Entity.
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id: nil, card: nil) ⇒ Entity
Returns a new instance of Entity.
8 9 10 11 12 13 |
# File 'lib/hearthstone/models/entity.rb', line 8 def initialize(id: nil, card: nil) @id = id @card = card @damaged = 0 @attachments = [] end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
6 7 8 |
# File 'lib/hearthstone/models/entity.rb', line 6 def @attachments end |
#card ⇒ Object
Returns the value of attribute card.
5 6 7 |
# File 'lib/hearthstone/models/entity.rb', line 5 def card @card end |
#damaged ⇒ Object
Returns the value of attribute damaged.
5 6 7 |
# File 'lib/hearthstone/models/entity.rb', line 5 def damaged @damaged end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/hearthstone/models/entity.rb', line 5 def id @id end |
Instance Method Details
#attach(card) ⇒ Object
23 24 25 |
# File 'lib/hearthstone/models/entity.rb', line 23 def attach(card) << card end |
#attack ⇒ Object
39 40 41 |
# File 'lib/hearthstone/models/entity.rb', line 39 def attack self.card.attack end |
#current_health ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hearthstone/models/entity.rb', line 31 def current_health if self.card [0, self.card.health - damaged].max else 0 end end |
#detach(card) ⇒ Object
27 28 29 |
# File 'lib/hearthstone/models/entity.rb', line 27 def detach(card) .delete(card) end |
#eql?(other) ⇒ Boolean
15 16 17 |
# File 'lib/hearthstone/models/entity.rb', line 15 def eql?(other) other.equal?(id) || id == other.id end |
#hash ⇒ Object
19 20 21 |
# File 'lib/hearthstone/models/entity.rb', line 19 def hash id.hash end |
#name ⇒ Object
43 44 45 |
# File 'lib/hearthstone/models/entity.rb', line 43 def name card.name end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hearthstone/models/entity.rb', line 47 def to_s = .collect(&:name) = "" if .count > 0 = .join(", ") end if card case card.type when "Minion" "##{id} #{card.name} (#{attack}/#{current_health}) #{}" else "##{id} #{card.name}" end else "##{id} Hidden" end end |