class LOTS::Enemy
Attributes
health[RW]
int[RW]
lines[RW]
mana[RW]
name[RW]
str[RW]
Public Class Methods
new(args = nil)
click to toggle source
# 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
Public Instance Methods
attack(args)
click to toggle source
Enemy
attacks player
# 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