作者thryte.bbs@cpu.tfcis.org (風) 看板: itoc
標題自己寫了一個隨機送錢系統但有BUG...
時間動力核心 (2008/02/05 Tue 22:33:48)
這是我自己寫抽紅包金額的系統,
但是我原先市為了防止有人在抽第二次所以就直接在該用戶的檔案裡作紀錄,
不過,現在卻出現說抽過的人卻沒有辦法在進去該選項,
因為最初計畫是沒有抽過的會有一個畫面,
但是有抽過的又有另外一個畫面,
因此就不知道是哪邊出問題,
不知道有沒有大大能幫忙debug一下....
/*-------------------------------------------------------*/
/* redenvelope.c */
/*-------------------------------------------------------*/
/* target : 紅包時間 */
/* create : 08/02/05 */
/* update : / / */
/* author : s890510@bbs.cs.ntou.edu.tw */
/*-------------------------------------------------------*/
#include "bbs.h"
#ifdef HAVE_GAME
#define mouts(x,y,s) { move(x, y); outs(s); }
void get_screen(int mode)
{
FILE *fp;
char *fpath, buf[ANSILINELEN];
if (mode == 0)
{
fpath = "etc/game/redenvelope.again";
move(1, 0);
}
else if (mode == 1)
{
fpath = "etc/game/redenvelope.get";
move(2, 0);
}
if (!(fp = fopen(fpath, "r")))
return;
while (fgets(buf, ANSILINELEN, fp))
outs(buf);
fclose(fp);
}
void have_redenvelope()
{
while(1)
{
get_screen(0);
move(14,10);
prints("站長:領過了還想要領?門都沒有!");
}
}
void get_redenvelope()
{
char buf[80],fpath[64];
int rand_gold = 0,randum;
srand(time(NULL) + cuser.userno);
while(1)
{
if (vans("準備好要領紅包了嗎(Y/N)?")!= 'y')
break;
get_screen(1);
move(14,10);
prints("%s:嘿嘿~錢不太夠了,給點紅包錢吧~",cuser.userid);
move(15,10);
prints("站長:給你給你(隨便抓一些錢放進紅包),祝你新春愉快~");
randum = rand() % 2000000 + 1;
move(16,10);
if((randum % 9) == 0)
{
randum = (randum/100000)+1;
rand_gold = 1;
prints("系統:你獲得了%d金幣",randum);
cuser.gold += randum;
}
else
{
prints("系統:你獲得了%d銀幣",randum);
cuser.money += randum;
}
if(rand_gold == 1)
sprintf(buf, "%-13s領取了紅包 -%d 金 (%s)\n", cuser.userid, randum, Now());
else
sprintf(buf, "%-13s領取了紅包 -%d 銀 (%s)\n", cuser.userid, randum, Now());
f_cat(FN_RUN_REDENVELOPE_LOG, buf);
usr_fpath(fpath, cuser.userid, "redenvelope");
sprintf(buf, "已領取了紅包");
f_cat(fpath, buf);
}
}
void redenvelope()
{
char fpath[64];
usr_fpath(fpath, cuser.userid, "redenvelope");
if(fopen(fpath, "r"))
{
have_redenvelope();
}
else
{
get_redenvelope();
}
}
int main_redenvelope()
{
vs_bar("領紅包");
redenvelope();
return 0;
}
#endif /* HAVE_GAME */
--
=[﹎:�摃�◣��:﹎Origin ]|[ ���O���� cpu.tfcis.org ]|[�搟說�﹎:]=
=[﹊:�摃�╱��:﹊Author ]|[118-165-216-71.dynamic.hin]|[���插�﹊:]=