-- Text Adventure -- main loop (starter). -- -- Finish the TODOs so the game plays as described in the chapter -- page. -- -- Run from this folder: -- cd projects/04-text-adventure/starter -- lua main.lua local world = require("world") local current_room_id = world.start_id local inventory = {} -- TODO: write `describe(room)` that prints: -- -- -- -- -- Items here: (only if room has items) -- Exits: local function describe(room) -- your code here end -- TODO: write `go(direction)` that looks up the exit on the current -- room. If the exit exists, change current_room_id and describe the -- new room. Otherwise print "You cannot go that way." local function go(direction) -- your code here end -- TODO: write `take(item_name)` that looks for item_name in the -- current room's items list. If found, remove it from the room and -- add it to inventory. Print confirmation. If not found, print -- "There is no here." Return true if the player just picked -- up the gold coin so the main loop can end. local function take(item_name) -- your code here return false end -- TODO: write `show_inventory()` that prints inventory items -- separated by commas. If empty, print "You are carrying nothing." local function show_inventory() -- your code here end -- Helper: split a typed line into a verb and an argument. local function parse(input) local words = {} for w in string.gmatch(input, "%S+") do table.insert(words, w) end local verb = words[1] local arg = words[2] -- Items like "gold coin" are two words. Join everything after the -- verb into one argument string. if #words > 2 then arg = table.concat(words, " ", 2) end return verb, arg end describe(world.rooms[current_room_id]) while true do io.write("> ") local input = io.read() if input == nil then break end local verb, arg = parse(input) -- TODO: dispatch the verb to the right function. -- Suggested verbs: look, go, take, inv, quit. -- Remember to break out of the loop after quit or after take() -- returns true (gold coin picked up). end