荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Lg (创造人生的传奇), 信区: BBSAdmin
标 题: [转载] chess_go for firebird(转寄)
发信站: BBS 荔园晨风站 (Fri Oct 22 22:31:13 1999), 站内信件
【 以下文字转载自 Lg 的信箱 】
【 原文由 liugang.bbs@bbs.net.tsinghua.edu.cn 所发表 】
发信人: QuickBASIC (nju zhch), 信区: BBSMan_Dev
标 题: chess_go for firebird
发信站: BBS 水木清华站 (Sun Sep 26 11:02:21 1999)
信 息 潮 -- 文章阅读
--------------------------------------------------------------------------------
发信人: zhch@InfoTide (zhch), 信区: BBSBuilder
标 题: chess_go for fb3
发信站: 信 息 潮 (Sun Sep 26 10:08:31 1999)
转信站: InfoTide (local)
修改talk.c
(1)*********************先在最前面定义一些有关变量***************************
/*rem add by zhch for chess1*/
int a[21][21],chessx,chessy;
int chessturn,chesscolor,chesshand,chessmode=0;
(2)********************把下面这些代码加到talk.c的最后面***********************
int chessinit(int n)
{
int x,y;
char s[100];
sprintf(s,"%s plays chess.",currentuser.userid);
report(s);
chessmode=1;
chesscolor=n;
chesshand=1;
chessx=10;
chessy=10;
chessturn=n;
for(y=0;y<=20;y++)
for(x=0;x<=20;x++)
a[y][x]=-1;
for(y=1;y<=19;y++)
for(x=1;x<=19;x++)
a[y][x]=0;
chessshow();
}
int chessshow()
{
int y,x;
clear();
prints("┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼+┼┼┼┼┼+┼┼┼┼┼+┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼+┼┼┼┼┼+┼┼┼┼┼+┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼+┼┼┼┼┼+┼┼┼┼┼+┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
prints("└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘");
for(y=1;y<=19;y++)
for(x=1;x<=19;x++)
{
move(y-1,x*2-2);
if(a[y][x]==chesscolor)prints("●");
if(a[y][x]==3-chesscolor)prints("○");
}
move (3,43);
prints("CHESS_GO v0.9 for firebird BBS3.0\n");
move (5,43);
prints(" by zhch.nju 99.9");
move(12,43);
if(chesscolor==1)
prints(" Your color: ●");
if(chesscolor==2)
prints(" Your color: ○");
move(13,43);
prints(" Hand: %d ",chesshand);
move(14,43);
if(chessmode==1)
prints(" MODE: chess_go");
if(chessmode==2)
prints(" MODE: other chess");
move (20,0);
prints("LEFT:'a', RIGHT:'s', UP:'w', DOWN:'z', PUTS:' ', CHANGEMODE:'#',
EXIT:^D.\n");
if(chessturn==1){prints("Now you move, don't be too slow :).\n");}
else{prints("Now the other player moves, please wait..\n");}
move(chessy-1,(chessx-1)*2);
}
int chessmain(int color, int ch)
{
if(color!=chessturn)return;
if(ch=='w'&&chessy>1)chessy--;
if(ch=='z'&&chessy<19)chessy++;
if(ch=='a'&&chessx>1)chessx--;
if(ch=='s'&&chessx<19)chessx++;
if(ch=='#'){chessmode=3-chessmode;chessshow();}
move(chessy-1,chessx*2-2);
if(ch==' '&&a[chessy][chessx]==0)
{
a[chessy][chessx]=color;
chesshand++;
if(chessmode==1)chesstizi(3-color);
chessturn=3-chessturn;
chessshow();
}
}
int chesstizi(int thecolor)
{
int bak[21][21],y,x,flag;
for(y=0;y<=20;y++)
for(x=0;x<=20;x++)
bak[y][x]=a[y][x];
do
{
flag=0;
for(y=1;y<=19;y++)
for(x=1;x<=19;x++)
{
if(bak[y][x]==0)
{
bak[y][x]=-1;
if(bak[y-1][x]==thecolor){bak[y-1][x]=0;flag=1;}
if(bak[y+1][x]==thecolor){bak[y+1][x]=0;flag=1;}
if(bak[y][x-1]==thecolor){bak[y][x-1]=0;flag=1;}
if(bak[y][x+1]==thecolor){bak[y][x+1]=0;flag=1;}
}
}
} while(flag);
for(y=1;y<=19;y++)
for(x=1;x<=19;x++)
if(bak[y][x]==thecolor)a[y][x]=0;
}
(3)**********************修改do_talk()函数*****************************
*****************下面是修改后fb3.0的do_talk****************************
********只是增加了一些行,修改处均有注释标明,其他fb可参照修改。**************
int
do_talk(int fd)
{
struct talk_win mywin, itswin;
char mid_line[ 256 ];
int page_pending = NA;
int i,i2;
int previous_mode;
#ifdef TALK_LOG
char mywords[80], itswords[80], buf[80];
int mlen=0, ilen=0;
time_t now;
mywords[0] = itswords[0] = '\0';
#endif
signal(SIGALRM, SIG_IGN);
endmsg();
refresh() ;
previous_mode=uinfo.mode;
modify_user_mode( TALK );
sprintf( mid_line, " %s (%s) 和 %s 正在畅谈中",
currentuser.userid, currentuser.username, save_page_requestor );
memset( &mywin, 0, sizeof( mywin ) );
memset( &itswin, 0, sizeof( itswin ) );
i = (t_lines-1) / 2;
mywin.eline = i - 1;
itswin.curln = itswin.sline = i + 1;
itswin.eline = t_lines - 2;
move( i, 0 );
printdash( mid_line );
move( 0, 0 );
talkobuflen = 0 ;
talkflushfd = fd ;
add_io(fd,0) ;
add_flush(talkflush) ;
while(YEA) {
int ch ;
if (talkrequest) page_pending = YEA;
if (page_pending)
page_pending = servicepage( (t_lines-1) / 2, mid_line );
ch = igetkey();
talkidletime=0;
if ( ch == ' ' )
{
igetkey();
igetkey();
continue;
}
if(ch == Ctrl('W')&&chessmode==0) /* add for chess */
{
chessmode=1;
send(fd,&ch,1,0);
chessinit(1);
}
if(ch == I_OTHERDATA) {
char data[80];
int datac;
register int i ;
datac = read(fd,data,80) ;
if(datac<=0)
break ;
for(i=0;i<datac;i++)
{
if(chessmode!=0){chessmain(2,data[i]);continue;}
/*add for chess*/
if(data[i]>=1&&data[i]<=4) {
moveto(data[i]-'\0',&itswin);
continue;
}
#ifdef TALK_LOG
/* Sonny.990514 add an robust and fix some logic problem */
/* Sonny.990606 change to different algorithm and fix the*/
/* existing do_log() overflow problem */
else if ( isprint2(data[i]) ) {
if ( ilen >= 80 )
{
itswords[80] = '\0';
(void) do_log(itswords, 2);
ilen = 0;
}
else
{
itswords[ilen] = data[i];
ilen++;
}
}
else if ( (data[i] == Ctrl('H') || data[i] == '\177') && !ilen )
{
itswords[ilen--] = '\0';
}
else if ( data[i] == Ctrl('M') || data[i] == '\r' ||
data[i] == '\n') {
itswords[ilen] = '\0';
(void) do_log(itswords, 2);
ilen = 0;
}
#endif
if (data[i]==Ctrl('W')) /*add for chess*/
{
chessmode=2;
chessinit(2);
}
do_talk_char( &itswin, data[i]);
}
} else {
if(ch == Ctrl('D') || ch == Ctrl('C'))
break ;
if(isprint2(ch) || ch == Ctrl('H') || ch == '\177'
|| ch == Ctrl('G')||chessmode!=0 ) /*modify for chess*/
{
talkobuf[talkobuflen++] = ch ;
if(talkobuflen == 80) talkflush();
if(chessmode!=0){chessmain(1,ch);continue;}/add for chess*/
#ifdef TALK_LOG
if ( mlen < 80 )
{
if ( (ch == Ctrl('H') || ch == '\177') && mlen != 0 )
{
mywords[mlen--] = '\0';
}
else
{
mywords[mlen] = ch;
mlen++;
}
}
else if ( mlen >= 80 )
{
mywords[80] = '\0';
(void) do_log(mywords, 1);
mlen = 0;
}
#endif
do_talk_char( &mywin, ch );
} else if (ch == '\n' || ch == Ctrl('M') || ch == '\r') {
#ifdef TALK_LOG
if ( mywords[0] != '\0' ) {
mywords[mlen++] = '\0';
(void) do_log(mywords, 1);
mlen = 0;
}
#endif
talkobuf[talkobuflen++] = '\r';
talkflush();
do_talk_char( &mywin, '\r' );
}
else if(ch>=KEY_UP&&ch<=KEY_LEFT)
{
moveto(ch-KEY_UP+1,&mywin);
talkobuf[talkobuflen++] = ch -KEY_UP+1;
if(talkobuflen == 80) talkflush() ;
}
else if (ch == Ctrl('E')) {
for(i2=0;i2<=10;i2++)
{
talkobuf[talkobuflen++] = '\r';
talkflush();
do_talk_char( &mywin, '\r' );
}
} else if (ch == Ctrl('P') && HAS_PERM(PERM_BASIC)) {
t_pager();
update_utmp();
update_endline();
}
}
}
add_io(0,0) ;
talkflush() ;
signal(SIGALRM, SIG_IGN);
add_flush(NULL) ;
modify_user_mode(previous_mode);
#ifdef TALK_LOG
/* edwardc.990106 聊天纪录 */
mywords[mlen] = '\0';
itswords[ilen] = '\0';
if ( mywords[0] != '\0' )
do_log(mywords, 1);
if ( itswords[0] != '\0' )
do_log(itswords, 2);
now = time(0);
sprintf(buf,"\n [1;34m通话结束, 时间: %s [m\n",Cdate(&now));
write(talkrec, buf, strlen(buf));
close(talkrec);
sethomefile(genbuf, currentuser.userid, "talklog");
getdata(23, 0, "是否寄回聊天纪录 [Y/n]: ", genbuf, 2, DOECHO, YEA);
switch ( genbuf[0] ) {
case 'n':
case 'N':
break;
default :
sethomefile(buf, currentuser.userid, "talklog");
sprintf(mywords, "跟 %s 的聊天记录 [%s]", partner, Cdate(&now)
+4);
mail_file(buf, currentuser.userid, mywords);
}
sethomefile(buf, currentuser.userid, "talklog");
unlink(buf);
#endif
return 0;
}
(4)*******玩法:先找人聊天,进入talk状态,然后在此状态下按^W,就可以开始下棋了
.********
*******^W者先行.下棋时按"#"可切换模式(chess_go模式会提子,other_chess模式不提子
,可*
******************************用来下五子棋等)
**************************************
**时间仓促,许多功能没有做,如棋谱记录,悔棋,升段制度等等。希望大家能共同把它完
善,**
******************************下面是运行时的界面,在fb3.0v7.27上编译通过
************
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼+┼┼┼┼┼+┼┼┼┼┼○┼┼┤ CHESS_GO v0.9 for firebird BBS3.0
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤ by zhch.nju 99.9
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼+┼┼┼┼┼+┼┼┼┼┼+┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤ Your color: ●
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤ Hand: 3
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤ MODE: chess_go
├●┼+┼┼┼┼┼+┼┼┼┼┼+┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤
└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘
LEFT:'a', RIGHT:'s', UP:'w', DOWN:'z', PUTS:' ', CHANGEMODE:'#', EXIT:^D.
Now you move, don't be too slow :).
--
※ 修改:.zhch 於 Sep 26 10:29:54 修改本文.[FROM: 202.119.46.31]
※ 来源:.信 息 潮 bbs.tide.dhs.org.[FROM: 202.119.46.31]
--------------------------------------------------------------------------------
分类讨论区 全部讨论区 上一篇 本讨论区 下一篇 回文章
--
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.119.37.7]
--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: ftp.szu.edu.cn]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店