五子棋双人c语言程序,tc 版双人对战的五子棋

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

map[i][j]=0;

cleardevice();

setbkcolor(13);

setcolor(1);

setfillstyle(1,2);

settextstyle(0,0,2);

outtextxy(10,440,"X:");

outtextxy(10,460,"Y:");

bar(BASEX,BASEY,BASEX+MX*BOXL,BASEY+MY*BOXL);

setlinestyle(0,0,3);

rectangle(BASEX,BASEY,BASEX+MX*BOXL,BASEY+MY*BOXL);

setlinestyle(0,0,1);

for(i=BASEX;i<=BASEX+MX*BOXL;i+=BOXL)

line(i,BASEY,i,BASEY+MY*BOXL);

for(i=BASEY;i<=BASEY+MY*BOXL;i+=BOXL)

line(BASEX,i,BASEX+MX*BOXL,i);

putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);

}

void ShowScore()

{char s[20];

setcolor(3);

settextstyle(0,0,2);

outtextxy(512,13,"WHITE");

itoa(WhiteScore,s,10);

outtextxy(512,33,s);

setcolor(4);

settextstyle(0,0,2);

outtextxy(512,73,"RED");

itoa(RedScore,s,10);

outtextxy(512,93,s);

}

int Down()

{ static  int px=0,py=0;

long key=0;

switch(who)

{case 0:

do{

while(bioskey(1)==0)

{

if(CheckMouse()==1) return 0;

}

px=x;

py=y;

key=bioskey(0);

switch(key)

{ case KEY_W :case KEY_w : if(y-1>0) y--;break;

case KEY_S :case KEY_s : if(y+1

case KEY_A :case KEY_a : if(x-1>0) x--;break;

case KEY_D :case KEY_d :if(x+1

case ESC   : return 3;

case SPACE :

if(map[x][y]==0)

{   map[x][y]=1;

putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Red,1);

return 0;

}

}

Showxy(x,y);

if( x==px && y==py) continue;

putimage(BASEX+px*BOXL-BOXL/2,BASEY+py*BOXL-BOXL/2,Sign,1);

putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);

}while(1);

case 1:

do

{

while(bioskey(1)==0)

{

if(CheckMouse()==1) return 0;

}

px=x;

py=y;

key=bioskey(0);

switch(key)

{ case UP:   if(y-1>0)  y--;break;

case DOWN: if(y+1

case LEFT: if(x-1>0)  x--;break;

case RIGHT:if(x+1

case ESC  :return 3;

case ENTER:

if(map[x][y]==0)

{   map[x][y]=2;

putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,White,1);

return 0;

}

}

if( x==px && y==py) continue;

Showxy(x,y);

putimage(BASEX+px*BOXL-BOXL/2,BASEY+py*BOXL-BOXL/2,Sign,1);

putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);

}while(1);

}

}

int ChaiJue()

{

int i,j,n=0,p;

i=x;

j=y;

while(i!=0 && j!=0)

{ i--;

j--;

};

p=1;

n=0;

while(i!=MX-1 &&j!=MY-1)

{ if(map[i][j]!=0)

{

if(map[i][j]==p)

{   n++;

if(n==5) return p;

}

else

{

p=map[i][j];

n=1;

}

}

else

n=0;

i++;

j++;

}

i=x;

j=y;

while(i!=0 && j!=MY-1)

{ i--;

j++;

};

p=1;

n=0;

while(i!=MX-1 &&j!=0)

{ if(map[i][j]!=0)

{

if(map[i][j]==p)

{   n++;

if(n==5) return p;

}

else

{

p=map[i][j];

n=1;

}

}else

n=0 ;

i++;

j--;

}

p=1;

n=0;

for(i=0;i

{   if(map[i][y]==0)

{n=0;continue;}

if(map[i][y]==p)

{   n++;

if(n==5) return p;

}

else

{

p=map[i][y];

n=1;

}

}

p=1;

n=0;

for(i=0;i

{ if(map[x][i]==0)

{n=0;continue;}

if(map[x][i]==p)

{   n++;

if(n==5) return p;

}

else

{

p=map[x][i];

n=1;

}

}

return 0;

}

int main()

{     int Over=0;

int Win=0;

InitGra();

InitGame();

while(! Over)

{

Win=0;

x=MX/2;

y=MY/2;

DrawGround();

ShowScore();

Showxy(x,y);

while(!Win)

{  message();

if( Down() ) break;

Win=ChaiJue();

who=!who;

}

setcolor(4);

settextstyle(1,0,4);

if(Win==2)

{       who=1;

WhiteScore+=100;

settextstyle(0,0,5);

outtextxy(100,230,"the White win!");

}

else if(Win==1)

{       who=0;

RedScore+=100;

settextstyle(0,0,5);

outtextxy(100,230,"the Red win!");

}else

{

Over=1;

}

if(Over!=1)

sleep(2);

}

free(White);

free(Red);

free(Sign);

closegraph();

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一个很好的五子棋c语言程序代码,最重要的是能运行正确!!! #include #include #include #include #include #define CROSSRU 0xbf /*右上角点*/ #define CROSSLU 0xda /*左上角点*/ #define CROSSLD 0xc0 /*左下角点*/ #define CROSSRD 0xd9 /*右下角点*/ #define CROSSL 0xc3 /*左边*/ #define CROSSR 0xb4 /*右边*/ #define CROSSU 0xc2 /*上边*/ #define CROSSD 0xc1 /*下边*/ #define CROSS 0xc5 /*十字交叉点*/ /*定义棋盘左上角点在屏幕上的位置*/ #define MAPXOFT 5 #define MAPYOFT 2 /*定义1号玩家的操作键键码*/ #define PLAY1UP 0x1157/*上移--'W'*/ #define PLAY1DOWN 0x1f53/*下移--'S'*/ #define PLAY1LEFT 0x1e41/*左移--'A'*/ #define PLAY1RIGHT 0x2044/*右移--'D'*/ #define PLAY1DO 0x3920/*子--空格键*/ /*定义2号玩家的操作键键码*/ #define PLAY2UP 0x4800/*上移--方向键up*/ #define PLAY2DOWN 0x5000/*下移--方向键down*/ #define PLAY2LEFT 0x4b00/*左移--方向键left*/ #define PLAY2RIGHT 0x4d00/*右移--方向键right*/ #define PLAY2DO 0x1c0d/*子--回车键Enter*/ /*若想在游戏中途退出, 可按 Esc 键*/ #define ESCAPE 0x011b /*定义棋盘上交叉点的状态, 即该点有无棋子 */ /*若有棋子, 还应能指出是哪个玩家的棋子 */ #define CHESSNULL 0 /*没有棋子*/ #define CHESS1 'O'/*一号玩家的棋子*/ #define CHESS2 'X'/*二号玩家的棋子*/ /*定义按键类别*/ #define KEYEXIT 0/*退出键*/ #define KEYFALLCHESS 1/*子键*/ #define KEYMOVECURSOR 2/*光标移动键*/ #define KEYINVALID 3/*无效键*/ 下载可看到完整的...

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值