From b1c3386ca4032ac5925969d759ae2e5bc015d1f8 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-FOJ6TK1\\Alex" Date: Wed, 12 Feb 2025 17:25:25 -0600 Subject: Final commit --- client/data/room.lua | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) (limited to 'client/data/room.lua') diff --git a/client/data/room.lua b/client/data/room.lua index 410b08e..d5d9b47 100644 --- a/client/data/room.lua +++ b/client/data/room.lua @@ -1,68 +1,68 @@ -local room = {} -local item = require("item") - -local room_base = { - add_item = function(self,itemname,itemdesc,itemlocation) - local newitem = item.create_new(itemname,itemdesc,itemlocation) - self.items[#self.items + 1] = newitem - end, - remove_item = function(self,itemname,itemdesc,itemlocation) - local to_remove = {} - for k,v in pairs(self.items) do - if v.name == itemname and v.desc == itemdesc and v.itemlocation == itemlocation then - to_remove[#to_remove + 1] = k - end - end - for k,v in pairs(to_remove) do - table.remove(self.items,v) - end - end, - get_items_names = function(self) - local ret = {} - for k,v in pairs(self.items) do - ret[#ret + 1] = v.name - end - return ret - end, - get_room_desc = function(self) - local sb = {} - sb[#sb + 1] = string.format("You are in a %s",self.name) - sb[#sb + 1] = string.format(self.desc) - for itemnum,item in pairs(self.items) do - sb[#sb + 1] = string.format("There is a %s %s",item.name,item.location) - end - for direction,room in pairs(self.go) do - if room == "exit" then - sb[#sb + 1] = string.format("There is an exit to the %s",direction) - else - local name = room.name - local sdir = string.lower(direction) - if sdir == "up" then - sb[#sb + 1] = string.format("There is a %s above you",name) - elseif sdir == "down" then - sb[#sb + 1] = string.format("There is a %s below you",name) - else - sb[#sb + 1] = string.format("There is a %s to the %s",name,direction) - end - end - end - return table.concat(sb,"\n") - end -} - -local room_m = {__index = room_base} - -function room.create_new(n,loc) - local ret = { - name=n, - items={}, - desc="", - go={}, - location=loc - } - print("Created room:",ret) - setmetatable(ret,room_m) - return ret -end -room.meta = room_m -return room +local room = {} +local item = require("item") + +local room_base = { + add_item = function(self,itemname,itemdesc,itemlocation) + local newitem = item.create_new(itemname,itemdesc,itemlocation) + self.items[#self.items + 1] = newitem + end, + remove_item = function(self,itemname,itemdesc,itemlocation) + local to_remove = {} + for k,v in pairs(self.items) do + if v.name == itemname and v.desc == itemdesc and v.itemlocation == itemlocation then + to_remove[#to_remove + 1] = k + end + end + for k,v in pairs(to_remove) do + table.remove(self.items,v) + end + end, + get_items_names = function(self) + local ret = {} + for k,v in pairs(self.items) do + ret[#ret + 1] = v.name + end + return ret + end, + get_room_desc = function(self) + local sb = {} + sb[#sb + 1] = string.format("You are in a %s",self.name) + sb[#sb + 1] = string.format(self.desc) + for itemnum,item in pairs(self.items) do + sb[#sb + 1] = string.format("There is a %s %s",item.name,item.location) + end + for direction,room in pairs(self.go) do + if room == "exit" then + sb[#sb + 1] = string.format("There is an exit to the %s",direction) + else + local name = room.name + local sdir = string.lower(direction) + if sdir == "up" then + sb[#sb + 1] = string.format("There is a %s above you",name) + elseif sdir == "down" then + sb[#sb + 1] = string.format("There is a %s below you",name) + else + sb[#sb + 1] = string.format("There is a %s to the %s",name,direction) + end + end + end + return table.concat(sb,"\n") + end +} + +local room_m = {__index = room_base} + +function room.create_new(n,loc) + local ret = { + name=n, + items={}, + desc="", + go={}, + location=loc + } + print("Created room:",ret) + setmetatable(ret,room_m) + return ret +end +room.meta = room_m +return room -- cgit v1.2.3-70-g09d2