|  | 
 
 
 楼主|
发表于 2015-4-13 13:34:15
|
显示全部楼层 
| 回复 2# xiaocao 
 主要的代码大概是这样的,就这么一小段罢了
 
 function followme(roomname,exits)                                                                                --如影随形系统,输入参数为当前房间名、方向,没有返回值,只修改imhere数据
 if followmatch(shouldbehere[1],roomname,exits)=="yes" then                        --如果当前房间的描述符合下一个shouldbehere的描述,说明走对了
 imhere={};                                                                                                                --首先把imhere清空
 table.insert(imhere,shouldbehere[1])                                                        --然后把shouldbehere的第一个位置作为目前所在地
 table.remove(shouldbehere,1)                                                                        --把shouldbehere的第一个位置去掉
 else                                                                                                                                --如果没走对,那么
 local maybehere={};
 for i=1,table.getn(imhere) do                                                                        --逐个可能的房间进行分析
 for k,v in pairs(map.exits)                                                                --每个房间逐个方向进行分析
 if followmatch(v.gto,roomname,exits)=="yes" then                --如果这个房间的这个方向通往的房间是当前房间的话,那么
 table.insert(maybehere,v.gto)                                                --把这个房间号加到maybe里去
 for j=1,table.getn(maybehere)-1 do                                        --maybe的号码从1到倒数第二个循环
 if maybehere[j]==maybehere[table.getn(maybehere)] then        --如果最后一个跟之前的有一致的
 table.remove(maybehere,table.getn(maybehere))                --把最后一个节点移除
 break;
 end
 end
 end
 end
 end
 imhere=maybehere;                                                                                                        --把maybe的数值给imhere,这样就知道目前可能在的节点了
 end
 end
 | 
 |