作者laechan (小太保)
看板mud_sanc
标题[程式] 关於分类法
时间Thu Nov 15 11:04:12 2007
假设一 mapping objs = (["档名" : 物件, ...]) 存放了所有武器
的档名及该档名所指向的物件。
定义一个 mixed types = ({"blade","lance","sword","axe",
"wand","rod","dagger","bow","gun"})
mapping objs;
static mixed types = ({"blade","lance","sword","axe",
"wand","rod","dagger","bow","gun"})
// 上述两个设为全域变数
void show_data(string str,int s)
{
// 第一次呼叫该函数时, s=0
string str="",files,t;
mixed keys_objs;
object ob;
if(s>sizeof(types))
{
write("资料显示完毕.\n");
return 1;
}
if(s==sizeof(types))
{
str="其它类武器总览:\n"+
"======================================================\n";
keys_objs=keys(objs);
foreach(files in keys_objs)
{
if(!ob=objs[files]) continue;
if((string)ob->query("type")!=t) continue;
str+=sprintf("%s %s\n",ob->query("short"),files);
}
write_file("/open/cmds/loadall_other.data",str);
write("其它类武器资料存档完成.\n"+
"全部工作已结束,感谢你的使用。\n");
return 1;
}
t=types[s];
str=t+" 类武器总览:\n"+
"======================================================\n";
keys_objs=keys(objs);
foreach(files in keys_objs)
{
if(!ob=objs[files]) continue;
if((string)ob->query("type")!=t) continue;
str+=sprintf("%s %s\n",ob->query("short"),files);
map_delete(objs,files);
}
write_file("/open/cmds/loadall_"+t+".data",str);
write(t+" 类武器资料存档完成, 请按 enter 键继续......");
input_to("show_data",0,s+1,str); // 重覆 input_to 自己, 同时 s+1
return 1;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 编辑: laechan 来自: 61.225.184.225 (11/15 11:19)
※ 编辑: laechan 来自: 61.225.184.225 (11/15 11:23)