diff options
| author | U-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net> | 2025-02-12 17:25:25 -0600 |
|---|---|---|
| committer | U-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net> | 2025-02-12 17:25:25 -0600 |
| commit | b1c3386ca4032ac5925969d759ae2e5bc015d1f8 (patch) | |
| tree | 74e7d8797afea9df12222e149e865134ddec9479 /client/data/room.lua | |
| parent | 0aae46ecc38005236210f7e243f02cac39ab1dc3 (diff) | |
| download | home_text_adventure-master.tar.gz home_text_adventure-master.tar.bz2 home_text_adventure-master.zip | |
Diffstat (limited to 'client/data/room.lua')
| -rw-r--r-- | client/data/room.lua | 136 |
1 files changed, 68 insertions, 68 deletions
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
|
