print("Welcome to LUA Adventure") run = true function get_command() io.output():write("> ") return io.input():read("*l") end x = 10 y = 10 function wait() coroutine.yield() end function end_seq() print "This game was written by:" wait() print " grumbel" wait() print " based on an idea by" wait() print " quickflash" wait() end function evilperson_func() local ex = 0 local ey = 0 local run = true while run do print(ex.."x"..ey..": evilperson is following you...") if ex > x then ex = ex - 1 else ex = ex + 1 end if ey > y then ey = ey - 1 else ey = ey + 1 end if ex == x and ey == y then print("evil person got you") run = false end coroutine.yield() end end threads = {} function dostuff_10x10() print "Doing stuff" table.insert(threads, coroutine.create(evilperson_func)) end function play_end_seq(co) while true do io.output():write("[press enter]") local enter = io.input():read("*l") coroutine.resume(co) if coroutine.status(co) == "dead" then run = false break end end end function do_stuff10x9() play_end_seq(coroutine.create(end_seq)) end rooms = {} rooms["10x9"] = { look = "You see the exit", next = "you see a door with a sign that you can't read.", dostuff = do_stuff10x9 } rooms["10x10"] = { look = "You see the starting point", next = "you see the starting point" } rooms["10x11"] = { dostuff = dostuff_10x10, look = "You see the evil person spawn button", next = "you see the evil person spawn button", } function look_neighbour(dir, x, y) local room = rooms[x.."x"..y] if room ~= nil and room.next ~= nil then print("To your "..dir.." "..room.next) else print("To your "..dir.." you see nothing.") end end while run do for i = 1, table.getn(threads) do coroutine.resume(threads[i]) end command = get_command() if command == "help" then print("Valid commands are:") print(" help") print(" up") print(" down") print(" left") print(" right") print(" where") print(" look") print("") elseif command == "quit" or command == nil then print("Bye, bye.") run = false elseif command == "up" then print("You go up.") y = y - 1 elseif command == "down" then print("You go down.") y = y + 1 elseif command == "left" then print("You go left.") x = x - 1 elseif command == "right" then print("You go right.") x = x + 1 elseif command == "where" then print("You are at "..x..", "..y..".") elseif command == "look" then local see = rooms[x.."x"..y] if see ~= nil and see.look ~= nil then print(see.look) else print("You see nothing here.") end print(" ") look_neighbour("left", x-1, y) look_neighbour("right", x+1, y) look_neighbour("up", x, y-1) look_neighbour("down", x, y+1) elseif command == "do" then local room = rooms[x.."x"..y] if room ~= nil then local dostuff = room.dostuff if dostuff ~= nil then dostuff() end end elseif command == "" then -- do nothing else print("Unknown command: "..command) end end -- EOF --