我是来当伸手党的 求PKU的可视地图的sprintf.....
RT....sprintf的对齐什么的头疼死了...
现在弄了一个超级简单的版本.... 而且还对不齐...
告诉我怎么做嘛...... 原帖由 fanzeyi 于 2010-12-22 11:14 PM 发表 http://pkuxkx.net/forum/images/common/back.gif
RT....
sprintf的对齐什么的头疼死了...
现在弄了一个超级简单的版本.... 而且还对不齐...
告诉我怎么做嘛......
看了几天后我终于明白你要什么了。就是那个小地图的代码吧?
void realtime_map(object me,object env)
{
object room_obj;
mapping exits;
int i;
string ln1,ln2,ln3,ln4,ln5,ln6;
string map_room, map_room2,jiantou,msg;
int map_room_width;
string setforroom;
string *dirs;
mapping alldirs=([
"northwest" : " ",
"north" : " ",
"northup" : " ",
"northeast" : " ",
"west" : " ",
"east" : " ",
"southeast" : " ",
"south" : " ",
"southwest" : " ",
"southdown" : " ",
"eastup" : " ",
"southup" : " ",
"northdown" : " ",
"eastdown" : " ",
"westup" : " ",
"westdown" : " ",
"enter" : " ",
"out" : " ",
"up" : " ",
"down" : " ",
"left" : " ",
"right" : " ",
]);
//add for save time
msg = env->query("realmap");
if(msg&&msg!="")
{
// printf(msg)
tell_object(me, msg);
return;
}
msg = "";
if( mapp(exits = env->query("exits")) )
{
if (me->query("position") != "zmuduser")
printf("\n");
dirs=keys(exits);
for(i=0;i< sizeof(dirs);i++)
{
if(!room_obj=find_object(exits]))
room_obj=load_object(exits]);
if(room_obj)
if (room_obj->query("short"))
alldirs]=room_obj->query("short");
}
jiantou="";
map_room2=alldirs["enter"];
if(alldirs["enter"]!=" "){
map_room2=alldirs["enter"];
jiantou=HIR+"∧"+NOR;
}
if(alldirs["up"]!=" "){
map_room2=alldirs["up"];
jiantou=HIC+"〓"+NOR;
}
if(alldirs["northdown"]!=" "){
map_room2=alldirs["northdown"];
jiantou="↓";
}
if(alldirs["northup"]!=" "){
map_room2=alldirs["northup"];
jiantou="↑";
}
if(alldirs["north"]!=" "){
map_room2=alldirs["north"];
jiantou="|";
}
map_room=map_room2;
for(i=0;i<(10+COLOR_D->color_len(map_room)-strlen(map_room2))/2;i++)
{
map_room =map_room+" ";
map_room =" "+map_room;
}
if (me->query("position") == "zmuduser")
{
msg = sprintf(" %"+(int)(COLOR_D->color_len(alldirs["northwest"])+10)+"s%-"+(int)(COLOR_D->color_len(map_room)+10)+"s%-"+(int)(COLOR_D->color_len(alldirs["northeast"])+10)+"s\n",
alldirs["northwest"],map_room,alldirs["northeast"]);
// printf(msg);
tell_object(me, msg);
setforroom = msg;
}
else{
msg = sprintf("%10s %-10s%-10s\n",
alldirs["northwest"],map_room,alldirs["northeast"]);
msg = replace_string(msg," "," ");
msg = replace_string(msg,alldirs["northwest"],
"<a target=nothing href=\\\"../Command/go northwest\\\">" + alldirs["northwest"] + "</a>");
msg = replace_string(msg,alldirs["north"],
"<a target=nothing href=\\\"../Command/go north\\\">" + map_room + "</a>");
msg = replace_string(msg,alldirs["northeast"],
"<a target=nothing href=\\\"../Command/go northeast\\\">" + alldirs["northeast"] + "</a>");
msg = replace_string(msg,alldirs["northup"],
"<a target=nothing href=\\\"../Command/go northup\\\">" + alldirs["northup"] + "</a>");
msg = replace_string(msg,alldirs["northdown"],
"<a target=nothing href=\\\"../Command/go northdown\\\">" + alldirs["northdown"] + "</a>");
msg = replace_string(msg,alldirs["enter"],
"<a target=nothing href=\\\"../Command/go enter\\\">" + alldirs["enter"] + "</a>");
msg = replace_string(msg,alldirs["up"],
"<a target=nothing href=\\\"../Command/go up\\\">" + alldirs["up"] + "</a>");
//write(msg);
ln1 = msg;
}
msg = sprintf("%s %s %s\n",
alldirs["northwest"]==" " ? "":"\",
jiantou,
alldirs["northeast"]==" " ? "":"/");
setforroom = setforroom + " " + msg;
if (me->query("position") == "zmuduser")
printf(" " + msg);
else
ln2 = (replace_string(" "+msg," "," "));
jiantou="";
map_room2=alldirs["westdown"];
if(map_room2!=" ")
jiantou="→";
if(alldirs["left"]!=" "){
map_room2=alldirs["left"];
jiantou="〈";
}
if(alldirs["westup"]!=" "){
map_room2=alldirs["westup"];
jiantou="←";
}
if(alldirs["west"]!=" "){
map_room2=alldirs["west"];
jiantou="--";
}
msg = sprintf(" %"+(int)(COLOR_D->color_len(map_room2)+10)+"s%s",map_room2,jiantou);
setforroom += msg;
if (me->query("position") == "zmuduser")
// printf(msg);
tell_object(me, msg);
else
{
msg = sprintf("%10s%s",map_room2,jiantou);
msg = replace_string(msg," "," ");
msg = replace_string(msg,alldirs["westdown"],
"<a target=nothing href=\\\"../Command/go westdown\\\">" + alldirs["westdown"] + "</a>");
msg = replace_string(msg,alldirs["left"],
"<a target=nothing href=\\\"../Command/go left\\\">" + alldirs["left"] + "</a>");
msg = replace_string(msg,alldirs["westup"],
"<a target=nothing href=\\\"../Command/go westup\\\">" + alldirs["westup"] + "</a>");
msg = replace_string(msg,alldirs["west"],
"<a target=nothing href=\\\"../Command/go west\\\">" + alldirs["west"] + "</a>");
ln3 = msg;
}
map_room2=env->query("short") ? env->query("short"): "----------";
map_room=HIG+map_room2+NOR;
map_room_width = (10+COLOR_D->color_len(map_room)-strlen(map_room))/2;
for(i=0;i<map_room_width;i++)
{
if(alldirs["east"]==" ")
map_room =map_room + " ";
else map_room=map_room + "-";
if(alldirs["west"]==" ")
map_room =" "+ map_room;
else map_room ="-"+map_room;
}
msg = sprintf("%s",map_room);
setforroom +=msg;
if (me->query("position") == "zmuduser")
tell_object(me, msg);
else
{
msg = replace_string(msg," "," ");
msg = replace_string(msg,map_room,
"<a target=nothing href=\\\"../Command/look\\\">" + map_room + "</a>");
ln3 += msg;
}
jiantou="";
map_room2=alldirs["eastup"];
if(map_room2!=" ")
jiantou="→";
if(alldirs["right"]!=" "){
map_room2=alldirs["right"];
jiantou="〉";
}
if(alldirs["eastdown"]!=" "){
map_room2=alldirs["eastdown"];
jiantou="←";
}
if(alldirs["east"]!=" "){
map_room2=alldirs["east"];
jiantou="--";
}
msg = sprintf("%s%-"+(int)(COLOR_D->color_len(map_room2)+10)+"s\n",jiantou,map_room2);
setforroom += msg;
if (me->query("position") == "zmuduser")
tell_object(me,msg);
else
{
msg = replace_string(msg," "," ");
msg = replace_string(msg,alldirs["eastdown"],
"<a target=nothing href=\\\"../Command/go eastdown\\\">" + alldirs["eastdown"] + "</a>");
msg = replace_string(msg,alldirs["left"],
"<a target=nothing href=\\\"../Command/go right\\\">" + alldirs["right"] + "</a>");
msg = replace_string(msg,alldirs["eastup"],
"<a target=nothing href=\\\"../Command/go eastup\\\">" + alldirs["eastup"] + "</a>");
msg = replace_string(msg,alldirs["east"],
"<a target=nothing href=\\\"../Command/go east\\\">" + alldirs["east"] + "</a>");
ln3 += msg;
}
jiantou="";
map_room2=alldirs["out"];
if(alldirs["out"]!=" "){
map_room2=alldirs["out"];
jiantou=HIR+"∨"+NOR;
}
if(alldirs["down"]!=" "){
map_room2=alldirs["down"];
jiantou=HIC+"〓"+NOR;
}
if(alldirs["southdown"]!=" "){
map_room2=alldirs["southdown"];
jiantou="↑";
}
if(alldirs["southup"]!=" "){
map_room2=alldirs["southup"];
jiantou="↓";
}
if(alldirs["south"]!=" "){
map_room2=alldirs["south"];
jiantou="|";
}
map_room=map_room2;
for(i=0;i<(10+COLOR_D->color_len(map_room2)-strlen(map_room2))/2;i++)
{
map_room =map_room + " ";
map_room =" "+map_room;
}
msg = sprintf("%s %s %s\n",
alldirs["southwest"]==" " ? "":"/",
jiantou,
alldirs["southeast"]==" " ? "":"\");
setforroom = setforroom + " " + msg;
if (me->query("position") == "zmuduser")
tell_object(me," "+msg);
else
ln4 = replace_string(" "+msg," "," ");
msg = sprintf("%"+(int)(COLOR_D->color_len(alldirs["southwest"])+10)+"s%-"+(int)(COLOR_D->color_len(alldirs["map_room"])+10)+"s%-"+(int)(COLOR_D->color_len(alldirs["southeast"])+10)+"s\n",
alldirs["southwest"],map_room,alldirs["southeast"]);
setforroom = setforroom + " " + msg;
if (me->query("position") == "zmuduser")
printf(" "+msg);
else
{
msg = sprintf("%10s %-10s%-10s\n",
alldirs["southwest"],map_room,alldirs["southeast"]);
msg = replace_string(msg," "," ");
msg = replace_string(msg,alldirs["southdown"],
"<a target=nothing href=\\\"../Command/go southdown\\\">" + alldirs["southdown"] + "</a>");
msg = replace_string(msg,alldirs["down"],
"<a target=nothing href=\\\"../Command/go down\\\">" + alldirs["down"] + "</a>");
msg = replace_string(msg,alldirs["southup"],
"<a target=nothing href=\\\"../Command/go southup\\\">" + alldirs["southup"] + "</a>");
msg = replace_string(msg,alldirs["south"],
"<a target=nothing href=\\\"../Command/go south\\\">" + map_room + "</a>");
msg = replace_string(msg,alldirs["out"],
"<a target=nothing href=\\\"../Command/go out\\\">" + alldirs["out"] + "</a>");
msg = replace_string(msg,alldirs["southeast"],
"<a target=nothing href=\\\"../Command/go southeast\\\">" + alldirs["southeast"] + "</a>");
msg = replace_string(msg,alldirs["southwest"],
"<a target=nothing href=\\\"../Command/go southwest\\\">" + alldirs["southwest"] + "</a>");
ln5 = msg;
}
}
else
{
map_room2=env->query("short") ? env->query("short"): "----------";
map_room=HIG+map_room2+NOR;
for(i=0;i<(10-strlen(map_room2))/2;i++)
{
if(alldirs["east"]==" ")
map_room =map_room + " ";
else map_room=map_room + "-";
if(alldirs["west"]==" ")
map_room =" "+ map_room;
else map_room ="-"+map_room;
}
msg = sprintf("\n %s\n",map_room);
// setforroom += msg;
if (me->query("position") == "zmuduser")
tell_object(me,msg);
}
if (me->query("position") != "zmuduser")
{
if( mapp(exits = env->query("exits")) ) {
dirs = keys(exits);
for(i=0; i<sizeof(dirs); i++)
if( (int)env->query_door(dirs, "status") & DOOR_CLOSED )
dirs = 0;
dirs -= ({ 0 });
if( sizeof(dirs)==0 )
ln6 = " 这里没有任何明显的出路。";
else if( sizeof(dirs)==1 )
ln6 = " 这里唯一的出口是 <a target=nothing href=\\\"../Command/go "+ dirs + "\\\"" + WEBRED + dirs+ "</a>" + WEBNOR + "。";
else {
ln6 = " 这里明显的出口是 ";
for (i = 0; i < sizeof(dirs) - 2; i++)
ln6 += sprintf("<a target=nothing href=\\\"../Command/go %s\\\">%s</a>、", dirs, dirs);
ln6 += sprintf("<a target=nothing href=\\\"../Command/go %s\\\">%s</a>和", dirs, dirs);
ln6 += sprintf("<a target=nothing href=\\\"../Command/go %s\\\">%s</a>", dirs, dirs);
ln6 += "。";
}
}
printf(JSP "parent.look_map(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")" NSP,
ln1,ln2,ln3,ln4,ln5,ln6);
}
env->set("realmap",setforroom);
return;
} 哇。。
这么好。。
本来我只是想要sprintf怎么排版的
没想到jason这么好啊啊啊
灰常感谢灰常感谢 标一个记号,留着备用。
页:
[1]