FC中国象棋源代码(中国象棋FC)
admin 发布:2022-12-19 18:55 160
本篇文章给大家谈谈FC中国象棋源代码,以及中国象棋FC对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
急需用c语言写中国象棋的代码,只要红色方布局和走棋
接上面中国象棋代码:
if( check_turn == 12) //相的走法规范
{ if((x == check_x y == check_y))
{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500);
}
else if( x = 15 (abs(y - check_y) == 8 abs(x - check_x) == 4))
{if((x == 22 (y == 11 || y == 27))||(x == 18
( y == 3 || y == 19 || y == 35)) ||(x == 14 (y == 11|| y ==27)))
{ if( map[(x+check_x)/2][(y+check_y)/2] == '+') check_main1(temp,temp1,turn,turn1,num,if_return,map);
else {printf("棋子卡住,不可执行"); Sleep(500); } }
else {printf("不合法的下法\n");Sleep(500); }
}
else {printf("不合法的下法\n"); Sleep(500); }
}
if( check_turn == 13) //士的走法规范
{ if((x == check_x y == check_y))
{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( abs(x - check_x)== 2 abs( y - check_y) == 4 ((x==22 (y == 15
|| y == 23)) || ( x == 20 y == 19) || ( x == 18 ( y == 15 || y == 23)))) {check_main1(temp,temp1,turn,turn1,num,if_return,map); }
else { printf("不合法的下法\n"); Sleep(500); } }
if( check_turn == 14) //将的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( ((abs(x - check_x)== 2 abs( y - check_y) == 0 )|| (abs(x - check_x)== 0
abs( y - check_y) == 4)) x = 18 x = 22 y = 15 y = 23 )
{ check_main1(temp,temp1,turn,turn1,num,if_return,map); }
else { printf("不合法的下法\n"); Sleep(500); } }
if( check_turn == 15) //炮的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( y == check_y )
{ int check_pao = 0;
if( x check_x)
{ for(j = check_x + 2; j= x ;j = j+ 2)
{ if(map[j][y] == '+' ); else check_pao++;}
if(check_pao == 1 temp == '+') // 直线行走但不可吃棋子 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); } }
else { for(j = check_x - 2; j= x;j = j - 2)
{ if(map[j][y] == '+' ); else { check_pao++;} }
if(check_pao == 1 temp == '+') //直线行走但不可吃棋子 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); } }
}
else if( x == check_x )
{ int check_pao = 0;
if( y check_y)
{ for(j = check_y + 4; j= y ;j = j+4)
{ if(map[x][j] == '+' ); else check_pao++;}
if(check_pao == 1 temp == '+') //直线行走但不可吃棋子 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); } }
else {for(j = check_y - 4; j= y;j = j - 4)
{if(map[x][j] == '+' ); else check_pao++;}
if(check_pao == 1 temp == '+') //直线行走但不可吃棋子 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); } }
}
else { printf("不合法的下法\n");Sleep(500); }
}
if( check_turn == 16) //卒的走法规范
{ if ( x = 14)
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( x == check_x - 2 y == check_y) check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); }
}
else{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if((x - check_x == 0 abs(y-check_y) ==4) ||( x - check_x == -2
abs(y-check_y) == 0)) check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); } }
}
}
else { if( check_turn == 20) //车的走法规范 (帅方)
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( y == check_y )
{ if( x check_x)
{ for(j = check_x + 2; j x;j = j + 2)
{ if(map[j][y] == '+'); else {printf("不合法的下法\n"); Sleep(500); break; } }
if( j = x) check_main2(temp,temp1,turn,turn1,num,if_return,map);
}
if( x check_x)
{ for(j = check_x - 2; j x;j = j - 2)
{ if(map[j][y] == '+'); else { printf("不合法的下法\n"); Sleep(500); break; } }
if( j = x) check_main2(temp,temp1,turn,turn1,num,if_return,map);
}
}
else if( x == check_x )
{ if( y check_y)
{ for(j = check_y + 4; j y;j = j + 4)
{ if(map[x][j] == '+'); else { printf("不合法的下法\n"); Sleep(500); break; } }
if( j = y) check_main2(temp,temp1,turn,turn1,num,if_return,map);
}
if( y check_y)
{ for(j = check_y - 4; j y;j = j - 4)
{ if(map[x][j] == '+'); else { printf("不合法的下法\n");Sleep(500); break; } }
if( j = y) check_main2(temp,temp1,turn,turn1,num,if_return,map);
}
}
else { printf("不合法的下法\n"); Sleep(500); }
}
if( check_turn == 21) //马的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if( (abs( x - check_x) == 2 abs( y - check_y) == 8)
map[check_x][(y+check_y)/2] =='+')
{ check_main2(temp,temp1,turn,turn1,num,if_return,map); }
else if( (abs( x - check_x) == 4 abs( y - check_y) == 4)
map[(x + check_x)/2][check_y] == '+' )
{ check_main2(temp,temp1,turn,turn1,num,if_return,map); }
else { printf("不合法的下法\n");Sleep(500); } }
if( check_turn == 22) //相的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if( x = 12 (abs(y - check_y) == 8 abs(x - check_x) == 4))
{ if((x == 4 (y == 11 || y == 27))||(x == 8 ( y == 3 || y == 19 || y == 35))
||(x == 12 (y == 11|| y ==27)))
{ if( map[(x+check_x)/2][(y+check_y)/2] == '+') check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("棋子卡住,不可执行");Sleep(500); } }
else {printf("不合法的下法\n");Sleep(500); }
}
else { printf("不合法的下法\n");Sleep(500); } }
if( check_turn == 23) //士的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if( abs(x - check_x)== 2 abs( y - check_y) == 4 ((x==4
(y == 15 || y == 23)) || ( x == 6 y == 19) || ( x == 8 ( y == 15 || y == 23))))
{ check_main2(temp,temp1,turn,turn1,num,if_return,map); }
else { printf("不合法的下法\n");Sleep(500); } }
if( check_turn == 24) //将的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if( ((abs(x - check_x)== 2 abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 abs( y - check_y) == 4)) x = 4 x = 8 y = 15 y = 23 )
{ check_main2(temp,temp1,turn,turn1,num,if_return,map); }
else {printf("不合法的下法\n");Sleep(500); } }
if( check_turn == 25) //炮的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if( y == check_y )
{ int check_pao = 0;
if( x check_x)
{ for(j = check_x + 2; j= x ;j = j+ 2)
{ if(map[j][y] == '+' ); else check_pao++;}
if(check_pao == 1 temp == '+') //直线行走但不可吃棋子 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
else { for(j = check_x - 2; j= x;j = j - 2)
{ if(map[j][y] == '+' ); else { check_pao++;} }
if(check_pao == 1 temp== '+') //直线行走但不可吃棋子 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
}
else if( x == check_x )
{ int check_pao = 0;
if( y check_y)
{ for(j = check_y + 4; j= y ;j = j+4)
{ if(map[x][j] == '+' ); else check_pao++;}
if(check_pao == 1 temp == '+') //直线行走但不可吃棋 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
else { for(j = check_y - 4 ; j= y;j = j - 4)
{ if(map[x][j] == '+' ); else check_pao++;}
if(check_pao ==1 temp == '+') //直线行走但不可吃棋子 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else if( check_pao == 2 temp != '+') //跳跃吃棋 check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
}
else { printf("不合法的下法\n");Sleep(500); }
}
if( check_turn == 26) //卒的走法规范
{ if( x = 12)
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( x == check_x + 2 y == check_y) check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
else{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");printf("还是你的回合"); Sleep(500); }
else if((x - check_x == 0 abs(y-check_y) ==4) ||( x - check_x == 2
abs(y-check_y) == 0)) check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
}
}
}
}
system("cls");
if( if_return) return;
for(i = 0; i 27; i++)puts(map[i]);
}
Sleep(5000);
}
int main( )
{ while(1)
{ xiangqi( );
printf("\n 重来,请按键.\n");
getch( );
}
return 0;
}
中国象棋的源代码
中国象棋源代码blackleft(){ int x,y,n; if(blackcurpos.y0) { blackcurpos.y--; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE)) { n=board[blacktemppos.x][blacktemppos.y]; drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE) drawselecursor(blackoldpos); drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackright(){ int x,y,n; if(blackcurpos.y8) { blackcurpos.y++; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE)) { n=board[blacktemppos.x][blacktemppos.y]; drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE) drawselecursor(blackoldpos); drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackdo(){ int i,j,x,y,n; if(blackstate==SELECTblackcanselect()) { if(board[blackcurpos.x][blackcurpos.y]=BLACKboard[blackcurpos.x][blackcurpos.y]0) { blackstate=MOVE; drawselecursor(blackcurpos); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; } } else if(blackstate==MOVEblackcanmove()) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; drawbmp(x,y,boardfile[blackoldpos.x][blackoldpos.y]); x=position[blackcurpos.x][blackcurpos.y].x; y=position[blackcurpos.x][blackcurpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); if(board[blackcurpos.x][blackcurpos.y]==RED_JIANG) { winner=BLACK; finish=1; return; } board[blackcurpos.x][blackcurpos.y]=n; board[blackoldpos.x][blackoldpos.y]=0; for(i=0;i=2;i++) for(j=3;j=5;j++) if(board[i][j]==BLACK_JIANG) {x=i;y=j;} for(i=x+1,j=y,n=0;i=9;i++) { if(board[i][j]==RED_JIANGn==0) {winner=RED;finish=1;break;} else if(board[i][j]!=0) n++; } turn=RED; redstate=SELECT; drawcursor(redcurpos); drawbmp(30,438,"bmp\\rzq.wfb"); /*转交控制权给红方*/ } }blackundo(){ int x,y,n; if(blackstate==MOVE) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; drawcursor(blackcurpos); blackstate=SELECT; }}/*----------------------------------------------------*/start(){ drawcursor(blackcurpos); drawbmp(30,438,"bmp\\bzq.wfb"); while(!finish) { key=getkey(); switch(key){ case RED_UP: if(turn==RED) redup(); break; case RED_DOWN: if(turn==RED) reddown(); break; case RED_LEFT: if(turn==RED) redleft(); break; case RED_RIGHT: if(turn==RED) redright(); break; case RED_DO: if(turn==RED) reddo(); break; case RED_UNDO: if(turn==RED) redundo(); break; case BLACK_UP: if(turn==BLACK) blackup(); break; case BLACK_DOWN: if(turn==BLACK) blackdown(); break; case BLACK_LEFT: if(turn==BLACK) blackleft(); break; case BLACK_RIGHT: if(turn==BLACK) blackright(); break; case BLACK_DO: if(turn==BLACK) blackdo(); break; case BLACK_UNDO: if(turn==BLACK) blackundo(); break; case ESCAPE: finish=1;break; } }}main(){ init(); initpos(); initchessmap(); drawbmp(0,0,"bmp\\board.wfb"); initdrawchess(); /*初始化光标位置*/ redcurpos.x=redoldpos.x=redtemppos.x=9; redcurpos.y=redoldpos.y=redtemppos.y=8; blackcurpos.x=blackoldpos.x=blacktemppos.x=0; blackcurpos.y=blackoldpos.y=blacktemppos.y=0;/*开始*/ start(); if(winner==RED) drawbmp(200,200,"bmp\\redwin.wfb"); else if(winner==BLACK) drawbmp(200,200,"bmp\\blackwin.wfb"); else drawbmp(200,200,"bmp\\exit.wfb"); getch(); end();}
VB 中国象棋源代码
你是要交作业吗?是要原创的吗?网上的可能很多人都有,但我自己写的还没有发表,哈哈。这里贴不了全的,我可以写一段给你看看,你觉得可以,就找我要吧,完全free的,能帮到你最好。
贴保存棋局和读取棋局部分的,你先看看:
Rem 读取棋局
Private Sub mnuRead_Click()
Dim s As String, i As Integer, t
If Dir(App.Path "\cchess.che") = "" Then MsgBox "没有棋局文件可以读入!请先保存棋局!", , "中国象棋": Exit Sub
Open App.Path "\cchess.che" For Input As #1
Input #1, s
Close #1
s = Replace(s, vbCrLf, "")
s = Trim(s)
t = Split(s, " ")
If UBound(t) 89 Then MsgBox "棋局文件已遭到破坏!请重新保存棋局!", , "中国象棋": Exit Sub
For i = 0 To 89
a(i) = Val(t(i))
Next
MsgBox "棋局文件已成功读入!", , "中国象棋"
End Sub
Rem 保存棋局
Private Sub mnuSave_Click()
Dim s As String, i As Integer
s = ""
For i = 0 To 89
s = s " " a(i)
Next
s = Trim(s)
Open App.Path "\cchess.che" For Output As #1
Print #1, s;
Close #1
MsgBox "当前棋局已成功保存!", , "中国象棋"
End Sub
FC中国象棋源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于中国象棋FC、FC中国象棋源代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 04-20简单的商城源代码(商城源代码免费下载)[20240420更新]
- 04-20php瀑布流源代码下载(瀑布线源码)[20240420更新]
- 04-20demo写代码(源代码设计笔记Demo)[20240420更新]
- 04-20中国源代码网(中国源代码网站)[20240420更新]
- 04-20高仿淘宝app源代码(高仿淘宝app源代码是什么)[20240420更新]
- 04-20网站源代码怎么生成网页(网站源代码怎么生成网页代码)
- 04-20关于winscp源代码的信息[20240420更新]
- 04-20java万年历源代码窗口版(Java实现万年历)[20240420更新]
- 04-20网页设计源代码和素材(网站设计源代码)
- 04-20dnf职业源代码(dnf代码大全)[20240420更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接