class MISSIONGAME::Player

Attributes

bonus[RW]
current_enemy[RW]
dead[RW]
in_combat[RW]
int[RW]
level[RW]
lives[RW]
name[RW]
points[RW]
str[RW]
x[RW]
y[RW]

Public Class Methods

new(args) click to toggle source
# File lib/player.rb, line 25
def initialize(args)
  name = args[:name]
  neworleans = args[:neworleans]
  @name = name
  @level = 1
  @lives = 100
  @bonus = 100
  @str = 5
  @int = 5
  @x = 1
  @y = neworleans.get_height
  @in_combat = false
  @current_enemy = nil
  @points = 0
  @dead = 0
  return "Welcome %{name}! Let's play!"
end

Public Instance Methods

attack(args) click to toggle source

Player attacks enemy

# File lib/player.rb, line 44
def attack(args)
  player = self
  enemy = args[:enemy]
  ui = args[:ui]

  # Does the player even hit the enemy?
  # We could use a hit chance stat here, but since we don't have one,
  # we'll just base it off the player/enemy stength discrepency.
  ui.enemy_info({ player: player })
  ui.player_info({ player: player })
  str_diff = (player.str - enemy.str) * 2
  hit_chance = rand(1...100) + str_diff + HIT_CHANCE_MODIFIER

  if (hit_chance > 50)
    # Determine value of the attack
    attack_value = rand(1...player.str) + ATTACK_VALUE_MODIFIER
    if attack_value > enemy.lives
      print 'You fought for your life and ' + 'hit'.light_yellow + ' ' +
              enemy.name.light_red + ' for ' +
              attack_value.to_s.light_white + " damages, killing him!\n"
      print 'You gain ' + enemy.points.to_s.light_white + " points.\n"
      return ENEMY_KILLED
    else
      print 'You fought for your life and ' + 'hit'.light_yellow + ' ' +
              enemy.name.light_red + ' for ' +
              attack_value.to_s.light_white + " damages, killing him!\n"
      return attack_value
    end
  else
    print 'You fought for your life and ' + 'missed'.light_red + ' ' +
            enemy.name + "!\n"
    return 0
  end
  return true
end
move(args) click to toggle source
# File lib/player.rb, line 80
def move(args)
  direction = args[:direction]
  neworleans = args[:neworleans]
  ui = args[:ui]
  story = args[:story]
  case direction
  when :up
    if @y > 1
      @y -= 1
    else
      ui.out_of_bounds
      return false
    end
  when :down
    if @y < neworleans.get_height
      @y += 1
    else
      ui.out_of_bounds
      return false
    end
  when :left
    if @x > 1
      @x -= 1
    else
      ui.out_of_bounds
      return false
    end
  when :right
    if @x < neworleans.get_width
      @x += 1
    else
      ui.out_of_bounds
      return false
    end
  end
  unless neworleans.check_area({ player: self, ui: ui, story: story })
    return false
  else
    return true
  end
end