Class: LOTS::Enemy
- Inherits:
-
Object
- Object
- LOTS::Enemy
- Defined in:
- lib/enemy.rb
Instance Attribute Summary collapse
-
#health ⇒ Object
Returns the value of attribute health.
-
#int ⇒ Object
Returns the value of attribute int.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#mana ⇒ Object
Returns the value of attribute mana.
-
#name ⇒ Object
Returns the value of attribute name.
-
#str ⇒ Object
Returns the value of attribute str.
Instance Method Summary collapse
-
#attack(args) ⇒ Object
Enemy attacks player.
-
#initialize(args = nil) ⇒ Enemy
constructor
A new instance of Enemy.
Constructor Details
#initialize(args = nil) ⇒ Enemy
Returns a new instance of Enemy.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/enemy.rb', line 33 def initialize(args = nil) # Pick a random enemy selected_enemy = ENEMY_CATALOG.sample[0] @name = selected_enemy[:name] @health = selected_enemy[:health] + rand(0..3) @mana = selected_enemy[:mana] + rand(0..3) @str = selected_enemy[:str] @lines = selected_enemy[:lines] @int = rand(2..6) end |
Instance Attribute Details
#health ⇒ Object
Returns the value of attribute health.
27 28 29 |
# File 'lib/enemy.rb', line 27 def health @health end |
#int ⇒ Object
Returns the value of attribute int.
30 31 32 |
# File 'lib/enemy.rb', line 30 def int @int end |
#lines ⇒ Object
Returns the value of attribute lines.
31 32 33 |
# File 'lib/enemy.rb', line 31 def lines @lines end |
#mana ⇒ Object
Returns the value of attribute mana.
28 29 30 |
# File 'lib/enemy.rb', line 28 def mana @mana end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/enemy.rb', line 26 def name @name end |
#str ⇒ Object
Returns the value of attribute str.
29 30 31 |
# File 'lib/enemy.rb', line 29 def str @str end |
Instance Method Details
#attack(args) ⇒ Object
Enemy attacks player
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/enemy.rb', line 45 def attack(args) enemy = self player = args[:player] # Does the enemy even hit the player? str_diff = (enemy.str - player.str) * 2 hit_chance = rand(1...100) + str_diff if (hit_chance > 30) # Determine value of the attack attack_value = rand(1...player.str) print enemy.name.light_red + " hits you for " + attack_value.to_s.light_yellow + " damage!\n" if attack_value > player.health return PLAYER_DEAD else return attack_value end else print enemy.name.light_red + " misses you!\n" end return true end |