class Core::Game::Inventory

strength is an arbitrary unit; in this context it’s 1 str == 1 kg of carrying

Attributes

capacity[RW]
strength[RW]

Public Class Methods

new(capacity, strength) click to toggle source
Calls superclass method
# File lib/game/inventory.rb, line 6
def initialize(capacity, strength)
  super(capacity)
  @capacity = capacity
  @strength = strength
  self.clear
end

Public Instance Methods

add(item) click to toggle source
# File lib/game/inventory.rb, line 12
def add(item)
  if self.size + 1 < @capacity and item.weight + weight < @strength
    self.push(item)
  end
end
remove(item, times=1) click to toggle source
# File lib/game/inventory.rb, line 17
def remove(item, times=1)
  removed = 0
  self.each { |other_item|
    if other_item.name == item.name
      self.delete_at(self.index(other_item))
      removed += 1
    end
    if removed >= times
      return
    end
  }
end
weight() click to toggle source
# File lib/game/inventory.rb, line 29
def weight
  weight = 0
  self.each { |item|
    weight += item.weight
  }
  return weight
end