diff --git a/utils.lua b/utils.lua --- a/utils.lua +++ b/utils.lua @@ -77,9 +77,16 @@ end; --[[ vroom with additional functionality ]] -function kh_vroom(disp, target, seen_level) +function kh_vroom(disp, target, nam, seen_level) + if (type(nam) == "number") then + seen_level = nam; + nam = disp; + end; + if (not nam) then + nam = disp; + end; return room { - nam = disp; + nam = nam; disp = disp; where = target; enter = _kh.vroom_enter; @@ -367,4 +374,81 @@ suit = function(tab) end; return obj(tab); +end; + +labyrinth = function(tab) + local position = "0"; + if (tab.position) then + position = tab.position; + end; + local lab; + lab = room { + var { + position = position; + }; + nam = tab.nam; + disp = tab.disp; + map = tab.map; + entered = function(s) + print(s.position); + path('e1'):disable(); + path('e2'):disable(); + path('e3'):disable(); + path('e4'):disable(); + path('ex'):disable(); + if (s.map[s.position].e1) then + path('e1'):enable(); + end; + if (s.map[s.position].e2) then + path('e2'):enable(); + end; + if (s.map[s.position].e3) then + path('e3'):enable(); + end; + if (s.map[s.position].e4) then + path('e4'):enable(); + end; + if (s.map[s.position].ex) then + path('ex'):enable(); + end; + if (type(tab.entered) == 'function') then + tab.entered(s); + end; + if (type(s.map[s.position].entered) == 'function') then + s.map[s.position].entered(s); + end; + end; + dsc = function(s) + if (type(tab.dsc) == "function") then + return tab.dsc(s); + else + return tab.dsc .. s.map[s.position].name; + end; + end; + way = { + kh_vroom(tab.dir1, function() + if (type(lab.position) == "function") then + lab.map[lab.position].left(lab); + end; + lab.position = lab.map[lab.position].e1; + return lab; + end, "e1"); + kh_vroom(tab.dir2, function() + lab.position = lab.map[lab.position].e2; + return lab; + end, "e2"); + kh_vroom(tab.dir3, function() + lab.position = lab.map[lab.position].e3; + return lab; + end, "e3"); + kh_vroom(tab.dir4, function() + lab.position = lab.map[lab.position].e4; + return lab; + end, "e4"); + kh_vroom(tab.exit, function() + return lab.map[lab.position].ex; + end, "ex"); + }; + }; + return lab; end; \ No newline at end of file