北大侠客行MUD论坛

 找回密码
 注册
搜索
热搜: 新手 wiki 升级
查看: 5786|回复: 3

我是来当伸手党的 求PKU的可视地图的sprintf.....

[复制链接]
发表于 2010-12-22 23:14:31 | 显示全部楼层 |阅读模式
RT....
sprintf的对齐什么的头疼死了...
现在弄了一个超级简单的版本.... 而且还对不齐...
告诉我怎么做嘛......
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
发表于 2010-12-26 23:59:13 | 显示全部楼层
原帖由 fanzeyi 于 2010-12-22 11:14 PM 发表
RT....
sprintf的对齐什么的头疼死了...
现在弄了一个超级简单的版本.... 而且还对不齐...
告诉我怎么做嘛......


看了几天后我终于明白你要什么了。就是那个小地图的代码吧?

  1. void realtime_map(object me,object env)
  2. {
  3.     object room_obj;
  4.     mapping exits;
  5.     int i;
  6.     string ln1,ln2,ln3,ln4,ln5,ln6;
  7.     string map_room, map_room2,jiantou,msg;
  8.     int map_room_width;
  9.     string setforroom;
  10.     string *dirs;
  11.     mapping alldirs=([      
  12.         "northwest"    : "          ",
  13.         "north"        : "          ",
  14.         "northup"    : "          ",
  15.         "northeast"    : "          ",
  16.         "west"        : "          ",
  17.         "east"        : "          ",
  18.         "southeast"    : "          ",
  19.         "south"        : "          ",
  20.         "southwest"    : "          ",
  21.         "southdown"    : "          ",
  22.         "eastup"    : "          ",
  23.         "southup"    : "          ",
  24.         "northdown"    : "          ",
  25.         "eastdown"    : "          ",
  26.         "westup"    : "          ",
  27.         "westdown"    : "          ",
  28.         "enter"        : "          ",
  29.         "out"        : "          ",
  30.         "up"        : "          ",
  31.         "down"        : "          ",
  32.         "left"        : "          ",
  33.         "right"        : "          ",
  34.         ]);  
  35.         //add for save time
  36.     msg = env->query("realmap");
  37.     if(msg&&msg!="")
  38.     {
  39. //        printf(msg)
  40.         tell_object(me, msg);
  41.         return;
  42.     }
  43.     msg = "";
  44.     if( mapp(exits = env->query("exits")) )
  45.     {                       
  46.         if (me->query("position") != "zmuduser")
  47.             printf("\n");
  48.         dirs=keys(exits);
  49.         for(i=0;i< sizeof(dirs);i++)
  50.         {
  51.             if(!room_obj=find_object(exits[dirs[i]]))
  52.                 room_obj=load_object(exits[dirs[i]]);
  53.             if(room_obj)
  54.                 if (room_obj->query("short"))
  55.                     alldirs[dirs[i]]=room_obj->query("short");
  56.         }
  57.         jiantou="  ";
  58.         map_room2=alldirs["enter"];
  59.         if(alldirs["enter"]!="          "){
  60.             map_room2=alldirs["enter"];
  61.             jiantou=HIR+"∧"+NOR;
  62.         }
  63.         if(alldirs["up"]!="          "){
  64.             map_room2=alldirs["up"];
  65.             jiantou=HIC+"〓"+NOR;
  66.         }
  67.         if(alldirs["northdown"]!="          "){
  68.             map_room2=alldirs["northdown"];
  69.             jiantou="↓";
  70.         }
  71.         if(alldirs["northup"]!="          "){
  72.             map_room2=alldirs["northup"];
  73.             jiantou="↑";
  74.         }
  75.         if(alldirs["north"]!="          "){
  76.             map_room2=alldirs["north"];
  77.             jiantou="|";
  78.         }
  79.         map_room=map_room2;
  80.         for(i=0;i<(10+COLOR_D->color_len(map_room)-strlen(map_room2))/2;i++)
  81.         {
  82.             map_room =map_room+" ";
  83.             map_room =" "+map_room;
  84.         }
  85.         if (me->query("position") == "zmuduser")
  86.         {
  87.             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",
  88.                 alldirs["northwest"],map_room,alldirs["northeast"]);
  89. //            printf(msg);
  90.             tell_object(me, msg);
  91.             setforroom = msg;
  92.         }
  93.         else{
  94.             msg = sprintf("%10s %-10s  %-10s\n",
  95.                     alldirs["northwest"],map_room,alldirs["northeast"]);
  96.             msg = replace_string(msg," "," ");
  97.             msg = replace_string(msg,alldirs["northwest"],
  98.                     "" + alldirs["northwest"] + "");
  99.             msg = replace_string(msg,alldirs["north"],
  100.                     "" + map_room + "");
  101.             msg = replace_string(msg,alldirs["northeast"],
  102.                     "" + alldirs["northeast"] + "");
  103.             msg = replace_string(msg,alldirs["northup"],
  104.                     "" + alldirs["northup"] + "");
  105.             msg = replace_string(msg,alldirs["northdown"],
  106.                     "" + alldirs["northdown"] + "");
  107.             msg = replace_string(msg,alldirs["enter"],
  108.                     "" + alldirs["enter"] + "");
  109.             msg = replace_string(msg,alldirs["up"],
  110.                     "" + alldirs["up"] + "");
  111.             //write(msg);
  112.             ln1 = msg;
  113.         }
  114.         msg = sprintf("%s   %s   %s\n",
  115.                 alldirs["northwest"]=="          " ? "  ":"\",
  116.                 jiantou,
  117.                 alldirs["northeast"]=="          " ? "  ":"/");
  118.         setforroom = setforroom + "                        " + msg;
  119.         if (me->query("position") == "zmuduser")
  120.             printf("                        " + msg);
  121.         else
  122.             ln2 = (replace_string("           "+msg," "," "));
  123.         jiantou="  ";
  124.         map_room2=alldirs["westdown"];
  125.         if(map_room2!="          ")
  126.             jiantou="→";
  127.         if(alldirs["left"]!="          "){
  128.             map_room2=alldirs["left"];
  129.             jiantou="〈";
  130.         }
  131.         if(alldirs["westup"]!="          "){
  132.             map_room2=alldirs["westup"];
  133.             jiantou="←";
  134.         }
  135.         if(alldirs["west"]!="          "){
  136.             map_room2=alldirs["west"];
  137.             jiantou="--";
  138.         }
  139.         msg = sprintf("             %"+(int)(COLOR_D->color_len(map_room2)+10)+"s%s",map_room2,jiantou);
  140.         setforroom += msg;
  141.         if (me->query("position") == "zmuduser")
  142. //                printf(msg);
  143.           tell_object(me, msg);
  144.         else
  145.         {
  146.             msg = sprintf("%10s%s",map_room2,jiantou);
  147.             msg = replace_string(msg," "," ");
  148.             msg = replace_string(msg,alldirs["westdown"],
  149.                     "" + alldirs["westdown"] + "");
  150.             msg = replace_string(msg,alldirs["left"],
  151.                     "" + alldirs["left"] + "");
  152.             msg = replace_string(msg,alldirs["westup"],
  153.                     "" + alldirs["westup"] + "");
  154.             msg = replace_string(msg,alldirs["west"],
  155.                     "" + alldirs["west"] + "");
  156.             ln3 = msg;
  157.         }
  158.         map_room2=env->query("short") ? env->query("short"): "----------";
  159.         map_room=HIG+map_room2+NOR;
  160.         map_room_width = (10+COLOR_D->color_len(map_room)-strlen(map_room))/2;
  161.         for(i=0;i
  162.         {
  163.             if(alldirs["east"]=="          ")
  164.                 map_room =map_room + " ";
  165.             else map_room=map_room + "-";
  166.             if(alldirs["west"]=="          ")
  167.                 map_room =" "+ map_room;
  168.             else map_room ="-"+map_room;
  169.         }
  170.         msg = sprintf("%s",map_room);
  171.         setforroom +=msg;
  172.         if (me->query("position") == "zmuduser")
  173.             tell_object(me, msg);
  174.         else
  175.         {
  176.             msg = replace_string(msg," "," ");
  177.             msg = replace_string(msg,map_room,
  178.                     "" + map_room + "");
  179.             ln3 += msg;
  180.         }
  181.         jiantou="  ";
  182.         map_room2=alldirs["eastup"];
  183.         if(map_room2!="          ")
  184.             jiantou="→";
  185.         if(alldirs["right"]!="          "){
  186.             map_room2=alldirs["right"];
  187.             jiantou="〉";
  188.         }
  189.         if(alldirs["eastdown"]!="          "){
  190.             map_room2=alldirs["eastdown"];
  191.             jiantou="←";
  192.         }
  193.         if(alldirs["east"]!="          "){
  194.             map_room2=alldirs["east"];
  195.             jiantou="--";
  196.         }
  197.         msg = sprintf("%s%-"+(int)(COLOR_D->color_len(map_room2)+10)+"s\n",jiantou,map_room2);
  198.         setforroom += msg;
  199.         if (me->query("position") == "zmuduser")
  200.             tell_object(me,msg);
  201.         else
  202.         {
  203.             msg = replace_string(msg," "," ");
  204.             msg = replace_string(msg,alldirs["eastdown"],
  205.                     "" + alldirs["eastdown"] + "");
  206.             msg = replace_string(msg,alldirs["left"],
  207.                     "" + alldirs["right"] + "");
  208.             msg = replace_string(msg,alldirs["eastup"],
  209.                     "" + alldirs["eastup"] + "");
  210.             msg = replace_string(msg,alldirs["east"],
  211.                     "" + alldirs["east"] + "");
  212.             ln3 += msg;
  213.         }
  214.         jiantou="  ";
  215.         map_room2=alldirs["out"];
  216.         if(alldirs["out"]!="          "){
  217.             map_room2=alldirs["out"];
  218.             jiantou=HIR+"∨"+NOR;
  219.         }
  220.         if(alldirs["down"]!="          "){
  221.             map_room2=alldirs["down"];
  222.             jiantou=HIC+"〓"+NOR;
  223.         }
  224.         if(alldirs["southdown"]!="          "){
  225.             map_room2=alldirs["southdown"];
  226.             jiantou="↑";
  227.         }
  228.         if(alldirs["southup"]!="          "){
  229.             map_room2=alldirs["southup"];
  230.             jiantou="↓";
  231.         }
  232.         if(alldirs["south"]!="          "){
  233.             map_room2=alldirs["south"];
  234.             jiantou="|";
  235.         }
  236.         map_room=map_room2;
  237.         for(i=0;i<(10+COLOR_D->color_len(map_room2)-strlen(map_room2))/2;i++)
  238.         {
  239.             map_room =map_room + " ";
  240.             map_room =" "+map_room;
  241.         }
  242.         msg = sprintf("%s   %s   %s\n",
  243.                 alldirs["southwest"]=="          " ? "  ":"/",
  244.                 jiantou,
  245.                 alldirs["southeast"]=="          " ? "  ":"\");
  246.         setforroom = setforroom + "                        " + msg;
  247.         if (me->query("position") == "zmuduser")
  248.             tell_object(me,"                        "+msg);
  249.         else
  250.             ln4 = replace_string("           "+msg," "," ");
  251.         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",
  252.                 alldirs["southwest"],map_room,alldirs["southeast"]);
  253.         setforroom = setforroom + "             " + msg;
  254.         if (me->query("position") == "zmuduser")
  255.             printf("             "+msg);
  256.         else
  257.         {
  258.             msg = sprintf("%10s %-10s  %-10s\n",
  259.                     alldirs["southwest"],map_room,alldirs["southeast"]);
  260.             msg = replace_string(msg," "," ");
  261.             msg = replace_string(msg,alldirs["southdown"],
  262.                     "" + alldirs["southdown"] + "");
  263.             msg = replace_string(msg,alldirs["down"],
  264.                     "" + alldirs["down"] + "");
  265.             msg = replace_string(msg,alldirs["southup"],
  266.                     "" + alldirs["southup"] + "");
  267.             msg = replace_string(msg,alldirs["south"],
  268.                     "" + map_room + "");
  269.             msg = replace_string(msg,alldirs["out"],
  270.                     "" + alldirs["out"] + "");
  271.             msg = replace_string(msg,alldirs["southeast"],
  272.                     "" + alldirs["southeast"] + "");
  273.             msg = replace_string(msg,alldirs["southwest"],
  274.                     "" + alldirs["southwest"] + "");
  275.             ln5 = msg;
  276.         }
  277.     }
  278.     else
  279.     {
  280.         map_room2=env->query("short") ? env->query("short"): "----------";
  281.         map_room=HIG+map_room2+NOR;
  282.         for(i=0;i<(10-strlen(map_room2))/2;i++)
  283.         {
  284.             if(alldirs["east"]=="          ")
  285.                 map_room =map_room + " ";
  286.             else map_room=map_room + "-";
  287.             if(alldirs["west"]=="          ")
  288.                 map_room =" "+ map_room;
  289.             else map_room ="-"+map_room;
  290.         }
  291.         msg = sprintf("\n                            %s\n",map_room);
  292.         //        setforroom += msg;
  293.         if (me->query("position") == "zmuduser")
  294.             tell_object(me,msg);
  295.     }
  296.     if (me->query("position") != "zmuduser")
  297.     {
  298.         if( mapp(exits = env->query("exits")) ) {
  299.             dirs = keys(exits);
  300.             for(i=0; i
  301.                 if( (int)env->query_door(dirs[i], "status") & DOOR_CLOSED )
  302.                     dirs[i] = 0;
  303.             dirs -= ({ 0 });
  304.             if( sizeof(dirs)==0 )
  305.                 ln6 = "    这里没有任何明显的出路。";
  306.             else if( sizeof(dirs)==1 )
  307.                 ln6 = "    这里唯一的出口是 " + WEBNOR + "。";
  308.             else {
  309.                 ln6 = "    这里明显的出口是 ";
  310.                 for (i = 0; i < sizeof(dirs) - 2; i++)
  311.                     ln6 += sprintf("%s、", dirs[i], dirs[i]);
  312.                 ln6 += sprintf("%s和", dirs[sizeof(dirs) - 2], dirs[sizeof(dirs) - 2]);
  313.                 ln6 += sprintf("%s", dirs[sizeof(dirs) - 1], dirs[sizeof(dirs) - 1]);
  314.                 ln6 += "。";
  315.             }
  316.         }
  317.         printf(JSP "parent.look_map("%s", "%s", "%s", "%s", "%s", "%s")" NSP,
  318.                 ln1,ln2,ln3,ln4,ln5,ln6);   
  319.     }
  320.     env->set("realmap",setforroom);
  321.     return;
  322. }
复制代码
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2010-12-28 20:36:42 | 显示全部楼层
哇。。
这么好。。
本来我只是想要sprintf怎么排版的
没想到jason这么好啊啊啊
灰常感谢灰常感谢
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
发表于 2011-1-16 16:58:01 | 显示全部楼层
标一个记号,留着备用。
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|北大侠客行MUD ( 京ICP备16065414号-1 )

GMT+8, 2024-3-28 04:14 PM , Processed in 0.009858 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表