class MISSIONGAME::Enemy
Attributes
bonus[RW]
int[RW]
lives[RW]
name[RW]
points[RW]
str[RW]
Public Class Methods
new(args = nil)
click to toggle source
# 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
Public Instance Methods
attack(args)
click to toggle source
Enemy
attacks player
# 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 return true end