看板SetupBBS
标 题[WindTop]接龙游戏
发信站元智大学风之塔 (Mon Jul 21 13:37:47 2003)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ncu!news.yzu!bbs.yzu
游戏规则写在游戏画面中了 :)
== src/maple/menu.c ==
+ "bin/seven.so:seven_main", PERM_VALID, - M_XMODE,
+ "Seven 接龙游戏",
== src/so 下新增下面那只程式 ==
/*-------------------------------------------------------*/
/* so/seven.c ( YZU WindTopBBS Ver 3.00 ) */
/*-------------------------------------------------------*/
/* author :
[email protected] */
/* target : 接龙游戏 */
/* create : 2001/01/12 */
/*-------------------------------------------------------*/
#include "bbs.h"
#define DO_LOG
int cards[52];
int seven[7];
int points[7];
/***************************************
画出牌
***************************************/
void
draw_card(card,x,y)
int card;
int x;
int y;
{
char *flower[] ={"C","D","H","S"};
char *number[] ={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
move(x ,y);prints("╭───╮");
move(x+1,y);prints("│%s │",(card<0)?" ":number[card%13]);
move(x+2,y);prints("│%s │",(card<0)?" ":flower[card%4]);
move(x+3,y);prints("│ │");
move(x+4,y);prints("│ │");
move(x+5,y);prints("╰───╯");
return ;
}
/***************************************
游戏说明
***************************************/
int
draw_explain(void)
{
int x=4;
clear();
vs_head("接龙游戏", str_site);
move(x+ 0,10);prints("【游戏说明】");
move(x+ 2,15);prints("(1) 在萤幕上方为牌墩,可以利用←、→或 j , k 切换。");
move(x+ 4,15);prints("(2) 在萤幕左下方为持牌 , 可以利用 c 切换。");
move(x+ 6,15);prints("(3) 当牌墩的牌是持牌的下一张或上一张,即可利用 Enter 吃牌。");
move(x+ 7,15);prints(" (只看点数,不看花色)");
move(x+ 9,15);prints("(4) 当牌墩的牌都吃完,及游戏获胜。");
move(x+11,15);prints("(5) 当持牌切换完且尚未吃完牌墩的牌,即游戏失败。");
move(x+13,15);prints("(6) 此游戏版权属於
[email protected]");
vmsg(NULL);
}
/***************************************
画出游戏牌的配置
***************************************/
void
draw_screen(void)
{
int i,j;
clear();
vs_head("接龙游戏", str_site);
for(i=0;i<7;i++)
for(j=0;j<i+1;j++)
{
draw_card((i==j)?cards[i]:-1,4+j,5+i*10);
}
}
/***************************************
画出游标
***************************************/
void
draw_cursor(location,mode)
int location;
int mode;
{
move(8+seven[location],9+location*10);
prints("%s",(mode==0)?" ":"●");
}
/***************************************
清除萤幕上的牌
***************************************/
void clear_card(location)
int location;
{
move(9+seven[location],5+location*10);
prints(" ");
}
/***************************************
游戏参数初始化
***************************************/
int
init(void)
{
int i,num,tmp;
for(i=0;i<52;i++)
cards[i] = i;
srand(time(0));
for(i=0;i<52;i++)
{
num = cards[i] ;
tmp = rand() % 52 ;
cards[i] = cards[tmp] ;
cards[tmp] = num;
}
for(i=0;i<7;i++)
{
seven[i] = i;
points[i] = cards[i] ;
}
return 0;
}
/***************************************
判断游戏是否结束
***************************************/
int
gameover(void)
{
int i;
for(i=0;i<7;i++)
if(seven[i] != -1 )
return 0;
return 1;
}
/***************************************
游戏主程式
***************************************/
int
play(void)
{
int location = 0;
int c,i;
int now_card=7;
int have_card=22;
int point;
draw_screen();
draw_cursor(location,1);
point = cards[now_card] ;
draw_card(cards[now_card++],14,5);
move(19,40);
prints("你还有 %2d 机会可以换牌",have_card);
move(18,10);
outz("\033[1;37;42m【操作说明】 [j]左移 [k]右移 [enter]吃牌 [c]换牌 [q]离开 \033[m");
do
{
c = vkey();
switch ( c )
{
case 'c' :
if(have_card == 0)
return -1;
have_card--;
move(19,40);
prints("你还有 %2d 机会可以换牌",have_card);
point = cards[now_card];
draw_card(cards[now_card++],14,5);
break;
case 'k' :
case KEY_RIGHT :
draw_cursor(location,0);
do
{
location = (location+1) % 7;
}while(seven[location] == -1);
draw_cursor(location,1);
break;
case 'j' :
case KEY_LEFT :
draw_cursor(location,0);
do
{
location = (location==0)?6:location-1;
}while(seven[location] == -1);
draw_cursor(location,1);
break;
case '\n' :
case ' ' :
if(points[location]%13-point%13 == 1 ||
points[location]%13-point%13 == -1 ||
points[location]%13-point%13 == 12 ||
points[location]%13-point%13 == -12)
{
point = points[location];
draw_card(point,14,5);
clear_card(location);
draw_cursor(location,0);
seven[location]--;
if(seven[location]>=0)
{
points[location] = cards[now_card];
draw_card(cards[now_card++],4+seven[location],5+location*10);
draw_cursor(location,1);
}
else
{
for(i=0;i<5;i++)
{
move(4+i,5+location*10);
prints(" ");
}
if( gameover() == 1) return have_card;
do
{
location = (location+1) % 7;
}while(seven[location] == -1);
draw_cursor(location,1);
}
}
break;
case 'q' :
return -2 ;
}
}while(1);
return 0;
}
int
seven_main(void)
{
int tmp;
draw_explain();
do
{
init();
clear();
tmp = play();
if(tmp>=0){
vmsg("恭喜你过关啦 !!");
}
else if(tmp==-1){
vmsg("挑战失败 !!");
}
else if(tmp==-2)
{
vmsg("下次再来玩唷 !!");
return 0;
}
if(vans("是否要继续? [y/N]") != 'y')
break;
}while(1);
return 0;
}
--
※ Origin: 元智大学 风之塔 <bbs.yzu.edu.tw>
※ From : bbs.yzu.edu.tw