Class: MISSIONGAME::Enemy
- Inherits:
-
Object
- Object
- MISSIONGAME::Enemy
- Defined in:
- lib/enemy.rb
Instance Attribute Summary collapse
-
#bonus ⇒ Object
Returns the value of attribute bonus.
-
#int ⇒ Object
Returns the value of attribute int.
-
#lives ⇒ Object
Returns the value of attribute lives.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/enemy.rb', line 29 def initialize(args = nil) # Pick a random enemy selected_enemy = ENEMY_CATALOG.sample[0] @name = selected_enemy[:name] @lives = selected_enemy[:lives] + rand(0..3) @bonus = selected_enemy[:bonus] + rand(0..3) @str = selected_enemy[:str] @points = selected_enemy[:points] @int = rand(2..6) end |
Instance Attribute Details
#bonus ⇒ Object
Returns the value of attribute bonus.
24 25 26 |
# File 'lib/enemy.rb', line 24 def bonus @bonus end |
#int ⇒ Object
Returns the value of attribute int.
26 27 28 |
# File 'lib/enemy.rb', line 26 def int @int end |
#lives ⇒ Object
Returns the value of attribute lives.
23 24 25 |
# File 'lib/enemy.rb', line 23 def lives @lives end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/enemy.rb', line 22 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
27 28 29 |
# File 'lib/enemy.rb', line 27 def points @points end |
#str ⇒ Object
Returns the value of attribute str.
25 26 27 |
# File 'lib/enemy.rb', line 25 def str @str end |
Instance Method Details
#attack(args) ⇒ Object
Enemy attacks player
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/enemy.rb', line 41 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(s)!\n" if attack_value > player.lives return PLAYER_DEAD else return attack_value end else print enemy.name.light_red + " sees you as an easy prey!\n" end true end |