回精華區
作者itoc (核心動力), 信區: itoc
標題Re: 請問rpg冒險者的排行榜應該怎麼做呢???
時間2004/10/27 Wed 10:42:33 Updated: 2004/10/27
※ 引述《comfan (難過  傷心)》之銘言:
> 秀出站上全部有參加RPG的使用者的列表資訊
> 【冒險者公會】
> 使用者代號   頭銜       經驗值  等級 體力 魔法 戰力 金幣
> allure       俠客       88956   9    100  100  100  0
> leechan      獨孤者     6767    6    100  100  100  0
> 請問一下  那個等級如果想要排序  由等級較高的往下排等級較低的放在較高者的下方

  得先做精華區這篇
  [功能] RPG 排行榜

  在 (A)nnounce 裡面新增資料,路徑為 allrpg

: toprpg.c

#define OUTFILE_RPGMAXHP BBSHOME"/gem/@/@-rpgmaxhp"
#define OUTFILE_RPGSTR   BBSHOME"/gem/@/@-rpgstr"
+ #define OUTFILE_ALLRPG BBSHOME"/gem/@/@allrpg"

: topusr.c

+ typedef struct
+ {
+   char userid[IDLEN + 1];
+   char usertitle[12];
+   int level;
+   int maxhp;
+ }      DATA2;

static DATA topmaxhp[TOPNUM];
static DATA topstr[TOPNUM];
+ static DATA2 alluserrpg[20000];    // 假設站上不超過 20000 個 id 
+ static int allusernum = 0;

static int
sort_compare(p1, p2)
  const void *p1;
  const void *p2;
{
  DATA *a1, *a2;

  a1 = (DATA *) p1;
  a2 = (DATA *) p2;

  return (a2->num - a1->num);
}


+ static int
+ sort2_compare(p1, p2)
+   const void *p1;
+   const void *p2;
+ {
+   DATA2 *a1, *a2;
+
+   a1 = (DATA2 *) p1;
+   a2 = (DATA2 *) p2;
+   return (a2->level - a1->level);
+ }


: topusr.c:topusr()

  sprintf(fpath, "%s/"FN_RPG, acct->userid);
  if ((fd = open(fpath, O_RDONLY)) < 0)
    return;
  read(fd, &rpg, sizeof(RPG));
  close(fd);

+ strcpy(alluserrpg[allusernum].userid, acct->userid);
+ strcpy(alluserrpg[allusernum].usertitle, rpg.usertitl);
+ alluserrpg[allusernum].level = rpg.level;
+ alluserrpg[allusernum].maxhp = rpg.maxhp;
+ allusernum++;

: toprpg.c:main()

  char c;
  int year, month, day;
  time_t now;
  struct tm *ptime;
+ int i;
+ FILE *fpall;

  ...
  ...

  for (c = 'a'; c <= 'z'; c++)
  {
    ...
    ...
  }

+ qsort(alluserrpg, allusernum, sizeof(DATA2), sort2_compare);
+
+ if (fpall = fopen(OUTFILE_ALLRPG, "w"))
+ {
+   fprintf(fpall, "\033[1;44m【冒險者公會】\033[m\n");
+   fprintf(fpall, "\033[30;47m%-13s%-11s%-5s%-5s \033[m\n",
+     "使用者代號", "頭銜", "等級", "血");
+
+   for (i = 0; i < allusernum; i++)
+   {
+     fprintf(fpall, "%-13s%-11.11s%5d%5d\n",
+       alluserrpg[i].userid, alluserrpg[i].usertitle,
+       alluserrpg[i].level, alluserrpg[i].maxhp);
+   }
+
+   fclose(fpall);
+ }

--
  Origin:  Maple-itoc˙動力核心  processor.tfcis.org 
  Author: itoc itoc.Dorm11.NCTU.edu.tw 發表
精華選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻