-- Inventory System -- module (starter). -- -- Define two classes: Item and Inventory. Export both as M.Item and -- M.Inventory at the end of the file. local M = {} ------------------------------------------------------------------- -- Item class ------------------------------------------------------------------- local Item = {} Item.__index = Item function Item.new(name, weight, value) -- TODO: build self with setmetatable, assign name, weight, value end function Item:describe() -- TODO: return a string like "sword (3.5kg, 50g)" end ------------------------------------------------------------------- -- Inventory class ------------------------------------------------------------------- local Inventory = {} Inventory.__index = Inventory function Inventory.new() -- TODO: build self with setmetatable, assign self.items = {} end function Inventory:add(item) -- TODO: table.insert(self.items, item) end function Inventory:remove(name) -- TODO: walk self.items; if an item has the matching name, -- table.remove it and return it. Otherwise return nil. end function Inventory:list() -- TODO: print "Inventory (N items):" then each item on its -- own line, then a totals line. end function Inventory:totalWeight() -- TODO: sum weights, return total end function Inventory:totalValue() -- TODO: sum values, return total end M.Item = Item M.Inventory = Inventory return M