Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local roomNow = "room1";
- local cave = {
- ["room1"] = {["south"] = "room3", ["east"] = "room2"}, --room1 - open south (r3), east (r2)
- ["room2"] = {["south"] = "room4", ["west"] = "room1"}, --room2 - open south (r4), west (r1)
- ["room3"] = {["north"] = "room1", ["east"] = "room4"}, --room3 - open north (r1), east (r4)
- ["room4"] = {} --room4 - won game
- };
- local gameloop = function(where, room)
- print("You are in " .. room .. ". Where you go?");
- local nextRoom = io.read();
- local check = where[room][nextRoom];
- check = check and check or room;
- if check == room then
- print("Wrong move");
- end;
- return check;
- end
- repeat
- roomNow = gameloop(cave, roomNow);
- until roomNow == "room4";
- print("Congratulations, you won!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement