作者BioStar.bbs@micro.bio.ncue.edu.tw (澎湖小雲雀) 看板: itoc
標題[問題] 星座男女配對... 改不出來... Q_Q
時間擎天崗 (Sun, 20 Jul 2003 04:04:39 +0800 (CST)) Updated: 2003/07/20
: menu.c 適當的選單加入
+ "bin/horoscope.so:x_astro", 0, - M_XMODE,
+ "Astro 【 我的星座 】",
+ "bin/horoscope.so:x_pair", 0, - M_XMODE,
+ "Pair 【 星座配對 】",
: src/so/Makefile
SO = admutil.so bank.so chat.so help.so vote.so xyz.so horoscope.so \
: etc/horoscope
建這目錄 etc/horoscope
etc/horoscope/ 下還要有三個檔案 day.hint moon.dat venus.dat
放在 http://cpu.twbbs.org/horoscope/
: src/so/horoscope.c 新增此程式
/*-------------------------------------------------------*/
/* horoscope.c ( NTHU CS MapleBBS Ver 3.10 ) */
/*-------------------------------------------------------*/
/* target : 星座男女配對 */
/* create : 03/07/20 */
/* update : / / */
/* author : BioStar.bbs@micro.bio.ncue.edu.tw */
/*-------------------------------------------------------*/
#include "bbs.h"
struct birth
{
int yy; /* 出生西元年 */
int mm; /* 出生月 */
int dd; /* 出生日 */
};
struct h_set
{
int s; /* 太陽星座 */
int m; /* 月亮星座 */
int v; /* 金星星座 */
};
static char name[12][5] =
{
"牡羊", "金牛", "雙子",
"巨蟹", "獅子", "處女",
"天秤", "天蠍", "射手",
"摩羯", "水瓶", "雙魚"
};
static char *said[21] =
{
"啊~~~啊~~~給我一杯忘情水~~~",
"唉~~~下一個情人會更好!",
"愛情是辛苦而沒有代價的....",
"唉...用後天的努力來補先天不足囉?",
"你知道人定勝天的道理嗎?",
"所有的成就都是靠九十九分的努力的!",
"愛情沒有天秤!輕重全看自己!",
"多給他一些關懷..會很有幫助的..",
"你們的感情要靠互相的包容!",
"十年修得同船渡...要好好珍惜!",
"感情是沒有理由的..喜歡就追吧!",
"嗯....有空出去約個會一定不錯!",
"嗯...做個愛可以增進小倆口的感情哦!",
"你們感情會與日俱增哦!",
"呵呵...你們就是容易互相吸引~~",
"嗯..你們就是這麼容易就相愛了~~~",
"像你們這麼相配實在是不容易.....",
"你們的戀愛會是非常甜蜜的哦~~~",
"天啊!你們真是天造地設的一對!",
"都相配到這種程度了..有沒有考慮結婚?",
"呵呵...你們是這站唯一出現滿分的情侶!"
};
/* ----------------------------------------------------- */
/* 太陽星座 */
/* ----------------------------------------------------- */
static int
SunHoro(Sa)
struct birth *Sa;
{
int Mm[12] = {20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
if (Sa->dd - Mm[Sa->mm - 1] >= 0)
return (Sa->mm + 9) % 12;
else
return (Sa->mm + 8) % 12;
}
/* ----------------------------------------------------- */
/* 金星星座 */
/* ----------------------------------------------------- */
static int /* 1:該年閏年 */
Lunar(year)
int year;
{
if (year % 400 == 0)
return 1;
if (year % 100 == 0)
return 0;
if (year % 4 == 0)
return 1;
return 0;
}
static int
MonthTotalDay(Sa)
struct birth *Sa;
{
int MD[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
return MD[Sa->mm - 1] + (Lunar(Sa->yy) && Sa->mm > 2);
}
static int
DayNumber(Sa) /* 傳給結構 birth, 傳回該天為第幾天 */
struct birth *Sa;
{
int i;
int TotalDay = 0;
for (i = 1929; i < Sa->yy; i++) /* 從 StartDay(1929) 算起 */
{
if (i < Sa->yy)
{
TotalDay = TotalDay + 365;
if (Lunar(i))
TotalDay++;
}
}
TotalDay += MonthTotalDay(Sa);
TotalDay += Sa->dd;
return TotalDay;
}
static int
VenusHoro(Sa)
struct birth *Sa;
{
int rc;
FILE *fp;
struct birth Venusx;
uschar VMon, VDay, VHr, VMin;
char Venus, buf[120];
if (!(fp = fopen("etc/horoscope/venus.dat", "r")))
return 0;
do
{
if (!fgets(buf, sizeof(buf), fp))
break;
} while (atoi(buf + 1) > Sa->yy);
while (fgets(buf, 12, fp))
{
if (*buf == '!')
{
Venus = buf[9];
buf[9] = '\0';
VMin = atoi(buf + 7);
buf[7] = '\0';
VHr = atoi(buf + 5);
buf[5] = '\0';
VDay = atoi(buf + 3);
buf[3] = '\0';
VMon = atoi(buf + 1);
buf[1] = '\0';
Venusx.yy = Sa->yy;
Venusx.mm = VMon;
Venusx.dd = VDay;
if (DayNumber(&Venusx) <= DayNumber(Sa))
{
rc = Venus >= 'A' ? Venus - 'A' + 9 : Venus - '1';
break;
}
}
}
fclose(fp);
return rc % 12;
}
/* ----------------------------------------------------- */
/* 月亮星座 */
/* ----------------------------------------------------- */
static int
MoonAddingDay(Day)
int Day;
{
int x[31] =
{
0, 1, 1, 1, 2, 2, 3,
3, 4, 4, 5, 5, 5, 6,
6, 7, 7, 8, 8, 9, 9,
10, 10, 10, 11, 11, 12, 12,
1, 1, 2
};
return x[Day - 1];
}
static int
MoonHoro(Sa)
struct birth *Sa;
{
int rc, j;
FILE *fp;
char Month, MoonBase, MoonMon;
char buf[60], *ptr;
Month = Sa->mm > 9 ? Sa->mm - 10 + 'A' : Sa->mm + '0';
if (!(fp = fopen("etc/horoscope/moon.dat", "r")))
return 0;
j = 1929;
while (j <= Sa->yy)
{
fgets(buf, 60, fp);
j++;
}
fclose(fp);
ptr = buf + 5;
while (*ptr == '!' && *ptr)
{
MoonMon = *(ptr + 1);
MoonBase = *(ptr + 2);
if (Month == MoonMon)
{
rc = ((MoonBase - 'A') + 12) % 12 + MoonAddingDay(Sa->dd);
break;
}
ptr += 3;
}
return rc % 12;
}
/* ----------------------------------------------------- */
/* 主程式 */
/* ----------------------------------------------------- */
static int
day_hint()
{
int j, Day;
FILE *fp;
char msg[150];
int MD[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
if (!(fp = fopen("etc/horoscope/day.hint", "r")))
return 0;
fgets(msg, 150, fp);
Day = MD[cuser.month - 1] + cuser.day - 1;
j = 0;
while (j < Day)
{
if (!fgets(msg, 150, fp))
break;
if (*msg == '#')
j++;
}
outs(" \033[1;36m在今天出生的你:\033[m \n");
for (j = 0; j < 4 && fgets(msg, 150, fp); j++)
prints(" \033[1;37m%s\033[m", msg);
fclose(fp);
}
static int
TogetherRule(x, y) /* 算出速配程度,傳回 0~100 */
struct h_set *x;
struct h_set *y;
{
int score;
/* 公式隨便寫的 */
score = (y->s - x->s) * 12 + (y->m - x->m) * 6 + (y->v - x->v) * 3;
if (score < 0)
score = -score;
return score % 101;
}
static void
ask_birth(row, b)
int row;
struct birth *b;
{
int year, month, day;
char buf[80];
int mmday[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
year = b->yy;
month = b->mm;
day = b->dd;
row++;
do
{
sprintf(buf, "生日-民國 %02d 年:", year);
if (vget(row, 0, buf, buf, 3, DOECHO))
year = atoi(buf);
} while (year < 40 || year > 90);
year += 1911;
mmday[1] = Lunar(year) ? 29 : 28;
row++;
do
{
sprintf(buf, "生日- %02d 月:", month);
if (vget(row, 0, buf, buf, 3, DOECHO))
month = atoi(buf);
} while (month < 1 || month > 12);
row++;
do
{
sprintf(buf, "生日- %02d 日:", day);
if (vget(row, 0, buf, buf, 3, DOECHO))
day = atoi(buf);
} while (day < 1 || day > mmday[month - 1]);
b->yy = year;
b->mm = month;
b->dd = day;
}
static void
get_hset(row, x, b)
int row;
struct h_set *x;
struct birth *b;
{
char buf[3];
x->s = SunHoro(b);
x->m = MoonHoro(b);
x->v = VenusHoro(b);
move(row++, 0);
outs("1)太陽 2)月亮 3)金星");
while (1)
{
move(row, 0);
prints(" [%s] [%s] [%s]", name[x->s], name[x->m], name[x->v]);
switch (vget(row + 1, 0, "[1-3]微調 [Q]確定:", buf, 3, LCECHO))
{
case '1':
x->s = (x->s + 1) % 12;
break;
case '2':
x->m = (x->m + 1) % 12;
break;
case '3':
x->v = (x->v + 1) % 12;
break;
case 'q':
return;
}
}
}
int
x_astro()
{
int Sun, Moon, Venus;
struct birth User;
User.mm = cuser.month;
User.dd = cuser.day;
User.yy = cuser.year + 1911;
Sun = SunHoro(&User);
Moon = MoonHoro(&User);
Venus = VenusHoro(&User);
vs_bar("我的星座");
move(8, 0);
prints(" 話說鼎鼎大名的 \033[1;36m%s\033[m 經過一次揚名世界的\n"
" \033[1;32;44m" BBSNAME "之旅後,大家皆稱他叫做 \033[1;33m%s\033[m\n"
" 他出生於\033[30;43m民國 %d 年 %d 月 %d 日\033[m\n",
cuser.userid, cuser.username, User.yy - 1911, User.mm, User.dd);
prints(" 主宰他的個性的太陽星座是 \033[1;33;41m%s座\033[m\n"
" 而影響他的本能行為的月亮星座是 \033[1;33;45m%s座\033[m\n"
" 以及影響個人吸引力與適應力的金星星座為 \033[1;33;44m%s座 \033[m\n",
name[Sun], name[Moon], name[Venus]);
day_hint();
vmsg(NULL);
return 0;
}
int
x_pair()
{
int i, score;
struct h_set hu, hp;
struct birth User, Pair;
vs_bar("星座配對");
move(2, 0);
outs("配對者:");
User.yy = cuser.year;
User.mm = cuser.month;
User.dd = cuser.day;
ask_birth(2, &User);
get_hset(7, &hu, &User);
move(12, 0);
outs("被配對者:");
Pair.yy = 0;
Pair.mm = 0;
Pair.dd = 0;
ask_birth(12, &Pair);
get_hset(17, &hp, &Pair);
move(2, 0);
clrtobot();
move(6, 0);
prints(" ID \033[1;36m%15s\033[m The one you love\n",
cuser.userid);
prints(" 暱稱 \033[1;33m%15s\033[m 心愛的人\n",
cuser.username);
prints(" 生日 民國%2d年%2d月%2d日\033[m"
" 民國%2d年%2d月%2d日\n",
User.yy - 1911, User.mm, User.dd,
Pair.yy - 1911, Pair.mm, Pair.dd);
prints(" 太陽星座 \033[1;33;41m%s座\033[m"
" %s座\n",
name[hu.s], name[hp.s]);
prints(" 月亮星座 \033[1;33;45m%s座\033[m"
" %s座\n",
name[hu.m], name[hp.m]);
prints(" 金星星座 \033[1;33;44m%s座\033[m"
" %s座\n",
name[hu.v], name[hp.v]);
score = TogetherRule(&hu, &hp);
outs("\n \033[1;34m總 得 分:\033[46m");
for (i = score / 2; i > 0; i--) /* 每 2 分 1 格 */
outc(' ');
prints("\033[40;37m %d/100\033[m\n", score);
prints("\n \033[1m" SYSOPNICK "給你們的評語:\033[33m%s\033[m",
said[score / 5]);
vmsg(NULL);
return 0;
}
--
| Origin | 彰化師大生物系 吟風‧眺月‧擎天崗 micro.bio.ncue.edu.tw
| Author | 163.23.212.99