Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local roomNow = "room1";
  2. local cave = {
  3.   ["room1"] = {["south"] = "room3", ["east"] = "room2"}, --room1 - open south (r3), east (r2)
  4.   ["room2"] = {["south"] = "room4", ["west"] = "room1"}, --room2 - open south (r4), west (r1)
  5.   ["room3"] = {["north"] = "room1", ["east"] = "room4"}, --room3 - open north (r1), east (r4)
  6.   ["room4"] = {} --room4 - won game
  7. };
  8.  
  9. local gameloop = function(where, room)
  10.   print("You are in " .. room .. ". Where you go?");
  11.   local nextRoom = io.read();
  12.   local check = where[room][nextRoom];
  13.   check = check and check or room;
  14.   if check == room then
  15.     print("Wrong move");
  16.   end;
  17.   return check;
  18. end
  19.  
  20. repeat
  21.   roomNow = gameloop(cave, roomNow);
  22. until roomNow == "room4";
  23. print("Congratulations, you won!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement