Sha256: 8c89a35a5f92b8c714b8a37a160bba94f8e13d9a75527d4c4f951154b37c38de
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
# lib/gemwarrior/inventory.rb # Collection of items a creature possesses module Gemwarrior class Inventory include Errors def initialize(inventory = []) @inventory = inventory end def list_contents contents_text = "You check your inventory" if @inventory.empty? return contents_text << ERROR_INVENTORY_EMPTY else @item_names = [] @inventory.each do |i| @item_names.push(i.name) end return contents_text << ": #{@inventory.map(&:name).join ', '}" end end def describe_item(item_name) if @inventory.map(&:name).include?(item_name) @inventory.each do |i| if i.name.eql?(item_name) return "#{i.description}" end end else ERROR_ITEM_INVENTORY_INVALID end end def add_item(cur_loc, item_name) cur_loc.items.each do |i| if i.name.eql?(item_name) if i.takeable @inventory.push(i) cur_loc.remove_item_from_location(item_name) return "Added #{item_name} to your increasing collection of bits of tid.\n" else ERROR_TAKE_ITEM_UNTAKEABLE end end end ERROR_TAKE_ITEM_INVALID end def remove_item(item_name) if @inventory.map(&:name).include?(item_name) @inventory.reject! { |item| item.name == item_name } puts "The #{item_name} has been thrown on the ground, but far out of reach, and you're much too lazy to go get it now, so it's as good as gone.\n" else puts ERROR_INVENTORY_REMOVE_INVALID end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gemwarrior-0.3.1 | lib/gemwarrior/inventory.rb |
gemwarrior-0.3.0 | lib/gemwarrior/inventory.rb |