|
发表于 2010-12-26 23:59:13
|
显示全部楼层
原帖由 fanzeyi 于 2010-12-22 11:14 PM 发表
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[dirs[i]]))
- room_obj=load_object(exits[dirs[i]]);
- if(room_obj)
- if (room_obj->query("short"))
- alldirs[dirs[i]]=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"],
- "" + alldirs["northwest"] + "");
- msg = replace_string(msg,alldirs["north"],
- "" + map_room + "");
- msg = replace_string(msg,alldirs["northeast"],
- "" + alldirs["northeast"] + "");
- msg = replace_string(msg,alldirs["northup"],
- "" + alldirs["northup"] + "");
- msg = replace_string(msg,alldirs["northdown"],
- "" + alldirs["northdown"] + "");
- msg = replace_string(msg,alldirs["enter"],
- "" + alldirs["enter"] + "");
- msg = replace_string(msg,alldirs["up"],
- "" + alldirs["up"] + "");
- //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"],
- "" + alldirs["westdown"] + "");
- msg = replace_string(msg,alldirs["left"],
- "" + alldirs["left"] + "");
- msg = replace_string(msg,alldirs["westup"],
- "" + alldirs["westup"] + "");
- msg = replace_string(msg,alldirs["west"],
- "" + alldirs["west"] + "");
- 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
- {
- 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,
- "" + map_room + "");
- 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"],
- "" + alldirs["eastdown"] + "");
- msg = replace_string(msg,alldirs["left"],
- "" + alldirs["right"] + "");
- msg = replace_string(msg,alldirs["eastup"],
- "" + alldirs["eastup"] + "");
- msg = replace_string(msg,alldirs["east"],
- "" + alldirs["east"] + "");
- 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"],
- "" + alldirs["southdown"] + "");
- msg = replace_string(msg,alldirs["down"],
- "" + alldirs["down"] + "");
- msg = replace_string(msg,alldirs["southup"],
- "" + alldirs["southup"] + "");
- msg = replace_string(msg,alldirs["south"],
- "" + map_room + "");
- msg = replace_string(msg,alldirs["out"],
- "" + alldirs["out"] + "");
- msg = replace_string(msg,alldirs["southeast"],
- "" + alldirs["southeast"] + "");
- msg = replace_string(msg,alldirs["southwest"],
- "" + alldirs["southwest"] + "");
- 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
- if( (int)env->query_door(dirs[i], "status") & DOOR_CLOSED )
- dirs[i] = 0;
- dirs -= ({ 0 });
- if( sizeof(dirs)==0 )
- ln6 = " 这里没有任何明显的出路。";
- else if( sizeof(dirs)==1 )
- ln6 = " 这里唯一的出口是 " + WEBNOR + "。";
- else {
- ln6 = " 这里明显的出口是 ";
- for (i = 0; i < sizeof(dirs) - 2; i++)
- ln6 += sprintf("%s、", dirs[i], dirs[i]);
- ln6 += sprintf("%s和", dirs[sizeof(dirs) - 2], dirs[sizeof(dirs) - 2]);
- ln6 += sprintf("%s", dirs[sizeof(dirs) - 1], dirs[sizeof(dirs) - 1]);
- ln6 += "。";
- }
- }
- printf(JSP "parent.look_map("%s", "%s", "%s", "%s", "%s", "%s")" NSP,
- ln1,ln2,ln3,ln4,ln5,ln6);
- }
- env->set("realmap",setforroom);
- return;
- }
复制代码 |
|