Method: MISSIONGAME::Enemy#attack

Defined in:
lib/enemy.rb

#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