中国象棋源代码blackleft(){ int x,y,n if(blackcurpos.y>0) {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.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)) {n=board[blacktemppos.x][blacktemppos.y] drawbmp(x,y,chessfile[n]) } if(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)drawselecursor(blackoldpos) drawcursor(blackcurpos) blacktemppos.x=blackcurpos.x blacktemppos.y=blackcurpos.y }}blackright(){ int x,y,n if(blackcurpos.y<8) {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.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)) {n=board[blacktemppos.x][blacktemppos.y] drawbmp(x,y,chessfile[n]) } if(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)drawselecursor(blackoldpos) drawcursor(blackcurpos) blacktemppos.x=blackcurpos.x blacktemppos.y=blackcurpos.y }}blackdo(){ int i,j,x,y,n if(blackstate==SELECT&&blackcanselect()) {if(board[blackcurpos.x][blackcurpos.y]<=BLACK&&board[blackcurpos.x][blackcurpos.y]>0){ blackstate=MOVE drawselecursor(blackcurpos) blackoldpos.x=blackcurpos.x blackoldpos.y=blackcurpos.y } } else if(blackstate==MOVE&&blackcanmove()) {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=0i<=2i++) for(j=3j<=5j++)if(board[i][j]==BLACK_JIANG) {x=iy=j}for(i=x+1,j=y,n=0i<=9i++){ if(board[i][j]==RED_JIANG&&n==0) {winner=REDfinish=1break} 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() breakcase 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=1break } }}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") elsedrawbmp(200,200,"bmp\\exit.wfb") getch() end()}你是要交作业吗?是要原创的吗?网上的可能很多人都有,但我自己写的还没有发表,哈哈。这里贴不了全的,我可以写一段给你看看,你觉得可以,就找我要吧,完全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
评论列表(0条)