❶ C語言編一個五子棋的程序

我也不會 ^_^,不過也許可以找到。但是你要這個做什麼?如果是作業還是自己做好,別人的你要是弄不明白也沒有用。

❷ 找五子棋源代碼c++

#include "iostream"
#include <iomanip>
using namespace std;
const int M=20;
const int N=20;
int main()
{
char wei[M][N];
int k,i,j,x,y,flag=0;
cout<<"歡迎使用簡易雙人對戰五子棋游戲"<<endl;
cout<<"五子棋棋譜如下:"<<endl;
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
{
wei[i][j]='-';
cout<<setw(3)<<setfill(' ')<<wei[i][j];
}
cout<<endl;
}
while(flag==0)
{
//紅方落子
cout<<"請紅方輸入落子位置:"<<endl;
loop1:
cout<<"請輸入落子的行數:";
cin>>x;
cout<<"請輸入落子的列數:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='*';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在這落子,請重新選擇落子位置:"<<endl;
goto loop1;
}
//判斷勝利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='*' && wei[i][j+1]=='*' && wei[i][j+2]=='*' && wei[i][j+3]=='*' && wei[i][j+4]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j]=='*' && wei[i+2][j]=='*' && wei[i+3][j]=='*' && wei[i+4][j]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j+1]=='*' && wei[i+2][j+2]=='*' && wei[i+3][j+3]=='*' && wei[i+4][j+4]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}

//藍方落子
cout<<"請藍方輸入落子位置:"<<endl;
loop2:
cout<<"請輸入落子的行數:";
cin>>x;
cout<<"請輸入落子的列數:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='#';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在這落子,請重新選擇落子位置:";
goto loop2;
}

//判斷勝利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='#' && wei[i][j+1]=='#' && wei[i][j+2]=='#' && wei[i][j+3]=='#' && wei[i][j+4]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j]=='#' && wei[i+2][j]=='#' && wei[i+3][j]=='#' && wei[i+4][j]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j+1]=='#' && wei[i+2][j+2]=='#' && wei[i+3][j+3]=='#' && wei[i+4][j+4]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}
}
return 0;
}

我運行過,沒有錯誤.

❸ 求一個用C語言編寫五子棋游戲的全部代碼.

這個程序還需要兩個文件,告訴我你郵箱,我發給你源程序前半部分/*載入頭文件*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>/*編譯預處理,定義按鍵碼*/
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
/*若想在游戲中途退出, 可按 Esc 鍵*/
#define ESC 0x011b
/*SPACE鍵表示落子*/
#define SPACE 0x3920/*設置偏移量*/
#define OFFSET 20
#define OFFSET_x 4
#define OFFSET_y 3
/*定義數組大小*/
#define N 19 /*定義全局變數*/
int status[N][N]; /*定義的數組,保存狀態*/
int step_x,step_y;/*行走的坐標*/
int key ; /*獲取按下的鍵盤的鍵*/
int flag; /*玩家標志*//*自定義函數原型*/
void DrawBoard();
void DrawCircle(int x,int y,int color);
void Alternation();
void JudgePlayer(int x,int y);
void Done();
int ResultCheck(int x,int y);
void WelcomeInfo();
void ShowMessage();/*定義函數*/
/*顯示歡迎信息函數*/
void WelcomeInfo()
{
char ch ;
/*移動游標到指定位置*/
gotoxy(12,4);
/*顯示歡迎信息*/
printf("Welcome you to gobang word!");
gotoxy(12,6);
printf("1.You can use the up,down,left and right key to move the chessman,");
gotoxy(12,8);
printf(" and you can press Space key to enter after you move it !");
gotoxy(12,10);
printf("2.You can use Esc key to exit the game too !");
gotoxy(12,12);
printf("3.Don not move the pieces out of the chessboard !");
gotoxy(12,14);
printf("DO you want to continue ?(Y/N)");
ch=getchar();
/*判斷程序是否要繼續進行*/
if(ch=='n'||ch=='N')
/*如果不繼續進行,則推出程序*/
exit(0);
}/*畫棋盤函數*/
void DrawBoard()
{
int x1,x2;
int y1,y2;
/*設置背景色*/
setbkcolor(2);
/*設置線條顏色*/
setcolor(1);
/*設置線條風格、寬度*/
setlinestyle(DOTTED_LINE,1,1); /*按照預設的偏移量開始畫棋盤*/
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET,(x1+OFFSET_x)*OFFSET,(y2+OFFSET_y)*OFFSET);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET,(x2+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET);
/*將各個點的狀態設置為0*/
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
status[x1][y1]=0; /*顯示幫助信息*/
setcolor(14);
/*設置字體、大小*/
settextstyle(1,0,1);
outtextxy((19+OFFSET_x)*OFFSET,(2+OFFSET_y)*OFFSET,"Player key:");
setcolor(9);
settextstyle(3,0,1);
outtextxy((19+OFFSET_x)*OFFSET,(4+OFFSET_y)*OFFSET,"UP--up ");
outtextxy((19+OFFSET_x)*OFFSET,(6+OFFSET_y)*OFFSET,"DOWN--down ");
outtextxy((19+OFFSET_x)*OFFSET,(8+OFFSET_y)*OFFSET,"LEFT--left");
outtextxy((19+OFFSET_x)*OFFSET,(10+OFFSET_y)*OFFSET,"RIGHT--right");
outtextxy((19+OFFSET_x)*OFFSET,(12+OFFSET_y)*OFFSET,"ENTER--space");
setcolor(14);
settextstyle(1,0,1);
outtextxy((19+OFFSET_x)*OFFSET,(14+OFFSET_y)*OFFSET,"Exit:");
setcolor(9);
settextstyle(3,0,1);
outtextxy((19+OFFSET_x)*OFFSET,(16+OFFSET_y)*OFFSET,"ESC");
}/*畫圓函數*/
void DrawCircle(int x,int y,int color)
{
setcolor(color);
/*設置畫圓線條的風格,寬度,這里設置為虛線*/
setlinestyle(SOLID_LINE,0,1);
x=(x+OFFSET_x)*OFFSET;
y=(y+OFFSET_y)*OFFSET;
/*以(x,y)為圓心,8為半徑畫圓*/
circle(x,y,8);
} /*交換行棋方函數*/
void Alternation()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
} /*對不同的行棋方畫不同顏色的圓函數*/
void JudgePlayer(int x,int y)
{
if(flag==1)
DrawCircle(x,y,15);
if(flag==2)
DrawCircle(x,y,4);
}/*判斷當前行棋方是否獲勝函數*/
int ResultCheck(int x,int y)
{
int j,k;
int n1,n2 ;
while(1)
{ /*對水平方向進行判斷是否有5個同色的圓*/
n1=0;
n2=0;
/*水平向左數*/
for(j=x,k=y;j>=1;j--)
{
if(status[j][k]==flag)
n1++;
else
break;
}
/*水平向右數*/
for(j=x,k=y;j<=18;j++)
{
if(status[j][k]==flag)
n2++;
else
break;
}
if(n1+n2-1>=5)
{
return(1);
} /*對垂直方向進行判斷是否有5個同色的圓*/
n1=0;
n2=0;
/*垂直向上數*/
for(j=x,k=y;k>=1;k--)
{
if(status[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下數*/
for(j=x,k=y;k<=18;k++)
{
if(status[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
} /*從左上方到右下方進行判斷是否有5個同色的圓*/
n1=0;
n2=0;
/*向左上方數*/
for(j=x,k=y;(j>=1)&&(k>=1);j--,k--)
{
if(status[j][k]==flag)
n1++;
else
break;
}
/*向右下方數*/
for(j=x,k=y;(j<=18)&&(k<=18);j++,k++)
{
if(status[j][k]==flag)
n2++;
else
break;
}
if(n1+n2-1>=5)
{
return(1);
} /*從右上方到左下方進行判斷是否有5個同色的圓*/
n1=0;
n2=0;
/*向右上方數*/
for(j=x,k=y;(j<=18)&&(k>=1);j++,k--)
{
if(status[j][k]==flag)
n1++;
else
break;
}
/*向左下方數*/
for(j=x,k=y;(j>=1)&&(k<=18);j--,k++)
{
if(status[j][k]==flag)
n2++;
else
break;
}
if(n1+n2-1>=5)
{
return(1);
}
return(0);
}
}

❹ c ++五子棋源代碼

#include "iostream" #include <iomanip> using namespace std; const int M=20; const int N=20; int main() { char wei[M][N]; int k,i,j,x,y,flag=0; cout<<"歡迎使用簡易雙人對戰五子棋游戲"<<endl; cout<<"五子棋棋譜如下:"<<endl; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) { wei[i][j]='-'; cout<<setw(3)<<setfill(' ')<<wei[i][j]; } cout<<endl; } while(flag==0) { //紅方落子 cout<<"請紅方輸入落子位置:"<<endl; loop1: cout<<"請輸入落子的行數:"; cin>>x; cout<<"請輸入落子的列數:"; cin>>y; if(wei[x][y]=='-') { wei[x][y]='*'; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) cout<<setw(3)<<setfill(' ')<<wei[i][j]; cout<<endl; } } else { cout<<"你不能在這落子,請重新選擇落子位置:"<<endl; goto loop1; } //判斷勝利 for(i=1;i<=M-4;i++) { for(j=1;j<=N-4;j++) { if(wei[i][j]=='*' && wei[i][j+1]=='*' && wei[i][j+2]=='*' && wei[i][j+3]=='*' && wei[i][j+4]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='*' && wei[i+1][j]=='*' && wei[i+2][j]=='*' && wei[i+3][j]=='*' && wei[i+4][j]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='*' && wei[i+1][j+1]=='*' && wei[i+2][j+2]=='*' && wei[i+3][j+3]=='*' && wei[i+4][j+4]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(flag==1) break; } } //藍方落子 cout<<"請藍方輸入落子位置:"<<endl; loop2: cout<<"請輸入落子的行數:"; cin>>x; cout<<"請輸入落子的列數:"; cin>>y; if(wei[x][y]=='-') { wei[x][y]='#'; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) cout<<setw(3)<<setfill(' ')<<wei[i][j]; cout<<endl; } } else { cout<<"你不能在這落子,請重新選擇落子位置:"; goto loop2; } //判斷勝利 for(i=1;i<=M-4;i++) { for(j=1;j<=N-4;j++) { if(wei[i][j]=='#' && wei[i][j+1]=='#' && wei[i][j+2]=='#' && wei[i][j+3]=='#' && wei[i][j+4]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='#' && wei[i+1][j]=='#' && wei[i+2][j]=='#' && wei[i+3][j]=='#' && wei[i+4][j]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='#' && wei[i+1][j+1]=='#' && wei[i+2][j+2]=='#' && wei[i+3][j+3]=='#' && wei[i+4][j+4]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(flag==1) break; } } } return 0; } 我運行過

❺ 五子棋的VC++代碼(初級)

http://www.codechina.net/resource/html/2006-06/14/151528.html

❻ 求一個C語言小程序(五子棋)源代碼

*******************************************************************/
/* ALEX_LEE 五子棋 C語言小程序 */
/* o(∩_∩)o...可以用來復習一下語言的小程序 */
/* My Blog:hi..com/alexlee321 */
/******************************************************************/

/**********************************************************/
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
/**********************************************************/
/* 定義符號常量 */

/*定義畫棋盤所需的製表符*/
#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/*無效鍵*/

/*定義符號常量: 真, 假 --- 真為1, 假為0 */
#define TRUE 1
#define FALSE 0

/**********************************************************/
/* 定義數據結構 */

/*棋盤交叉點坐標的數據結構*/
struct point
{
int x,y;
};

/**********************************************************/
/*自定義函數原型說明 */
void Init(void);
int GetKey(void);
int CheckKey(int press);
int ChangeOrder(void);
int ChessGo(int Order,struct point Cursor);
void DoError(void);
void DoOK(void);
void DoWin(int Order);
void MoveCursor(int Order,int press);
void DrawCross(int x,int y);
void DrawMap(void);
int JudgeWin(int Order,struct point Cursor);
int JudgeWinLine(int Order,struct point Cursor,int direction);
void ShowOrderMsg(int Order);
void EndGame(void);
/**********************************************************/

/**********************************************************/
/* 定義全局變數 */
int gPlayOrder; /*指示當前行棋方 */
struct point gCursor; /*游標在棋盤上的位置 */
char gChessBoard[19][19];/*用於記錄棋盤上各點的狀態*/
/**********************************************************/

/**********************************************************/
/*主函數*/
void main()
{
int press;
int bOutWhile=FALSE;/*退出循環標志*/

Init();/*初始化圖象,數據*/

while(1)
{
press=GetKey();/*獲取用戶的按鍵值*/
switch(CheckKey(press))/*判斷按鍵類別*/
{
/*是退出鍵*/
case KEYEXIT:
clrscr();/*清屏*/
bOutWhile = TRUE;
break;

/*是落子鍵*/
case KEYFALLCHESS:
if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/
DoError();/*落子錯誤*/
else
{
DoOK();/*落子正確*/

/*如果當前行棋方贏棋*/
if(JudgeWin(gPlayOrder,gCursor)==TRUE)
{
DoWin(gPlayOrder);
bOutWhile = TRUE;/*退出循環標志置為真*/
}
/*否則*/
else
/*交換行棋方*/
ChangeOrder();
}
break;

/*是游標移動鍵*/
case KEYMOVECURSOR:
MoveCursor(gPlayOrder,press);
break;

/*是無效鍵*/
case KEYINVALID:
break;
}

if(bOutWhile==TRUE)
break;
}

/*游戲結束*/
EndGame();
}
/**********************************************************/

/*界面初始化,數據初始化*/
void Init(void)
{
int i,j;
char *Msg[]=
{
"Player1 key:",
" UP----w",
" DOWN--s",
" LEFT--a",
" RIGHT-d",
" DO----space",
"",
"Player2 key:",
" UP----up",
" DOWN--down",
" LEFT--left",
" RIGHT-right",
" DO----ENTER",
"",
"exit game:",
" ESC",
NULL,
};

/*先手方為1號玩家*/
gPlayOrder = CHESS1;
/*棋盤數據清零, 即棋盤上各點開始的時候都沒有棋子*/
for(i=0;i<19;i++)
for(j=0;j<19;j++)
gChessBoard[i][j]=CHESSNULL;
/*游標初始位置*/
gCursor.x=gCursor.y=0;

/*畫棋盤*/
textmode(C40);
DrawMap();

/*顯示操作鍵說明*/
i=0;
textcolor(BROWN);
while(Msg[i]!=NULL)
{
gotoxy(25,3+i);
cputs(Msg[i]);
i++;
}

/*顯示當前行棋方*/
ShowOrderMsg(gPlayOrder);
/*游標移至棋盤的左上角點處*/
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*畫棋盤*/
void DrawMap(void)
{
int i,j;

clrscr();

for(i=0;i<19;i++)
for(j=0;j<19;j++)
DrawCross(i,j);

}

/*畫棋盤上的交叉點*/
void DrawCross(int x,int y)
{
gotoxy(x+MAPXOFT,y+MAPYOFT);
/*交叉點上是一號玩家的棋子*/
if(gChessBoard[x][y]==CHESS1)
{
textcolor(LIGHTBLUE);
putch(CHESS1);
return;
}
/*交叉點上是二號玩家的棋子*/
if(gChessBoard[x][y]==CHESS2)
{
textcolor(LIGHTBLUE);
putch(CHESS2);
return;
}

textcolor(GREEN);

/*左上角交叉點*/
if(x==0&&y==0)
{
putch(CROSSLU);
return;
}

/*左下角交叉點*/
if(x==0&&y==18)
{
putch(CROSSLD);
return;
}

/*右上角交叉點*/
if(x==18&&y==0)
{
putch(CROSSRU);
return;
}

/*右下角交叉點*/
if(x==18&&y==18)
{
putch(CROSSRD);
return;
}

/*左邊界交叉點*/
if(x==0)
{
putch(CROSSL);
return;
}

/*右邊界交叉點*/
if(x==18)
{
putch(CROSSR);
return;
}

/*上邊界交叉點*/
if(y==0)
{
putch(CROSSU);
return;
}

/*下邊界交叉點*/
if(y==18)
{
putch(CROSSD);
return;
}

/*棋盤中間的交叉點*/
putch(CROSS);
}

/*交換行棋方*/
int ChangeOrder(void)
{
if(gPlayOrder==CHESS1)
gPlayOrder=CHESS2;
else
gPlayOrder=CHESS1;

return(gPlayOrder);
}

/*獲取按鍵值*/
int GetKey(void)
{
char lowbyte;
int press;

while (bioskey(1) == 0)
;/*如果用戶沒有按鍵,空循環*/

press=bioskey(0);
lowbyte=press&0xff;
press=press&0xff00 + toupper(lowbyte);
return(press);
}

/*落子錯誤處理*/
void DoError(void)
{
sound(1200);
delay(50);
nosound();
}

/*贏棋處理*/
void DoWin(int Order)
{
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
nosound();

textcolor(RED+BLINK);
gotoxy(25,20);
if(Order==CHESS1)
cputs("PLAYER1 WIN!");
else
cputs("PLAYER2 WIN!");
gotoxy(25,21);
cputs(" \\<^+^>/");
getch();
}

/*走棋*/
int ChessGo(int Order,struct point Cursor)
{
/*判斷交叉點上有無棋子*/
if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL)
{
/*若沒有棋子, 則可以落子*/
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
textcolor(LIGHTBLUE);
putch(Order);
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
gChessBoard[Cursor.x][Cursor.y]=Order;
return TRUE;
}
else
return FALSE;
}

/*判斷當前行棋方落子後是否贏棋*/
int JudgeWin(int Order,struct point Cursor)
{
int i;
for(i=0;i<4;i++)
/*判斷在指定方向上是否有連續5個行棋方的棋子*/
if(JudgeWinLine(Order,Cursor,i))
return TRUE;
return FALSE;
}

/*判斷在指定方向上是否有連續5個行棋方的棋子*/
int JudgeWinLine(int Order,struct point Cursor,int direction)
{
int i;
struct point pos,dpos;
const int testnum = 5;
int count;

switch(direction)
{
case 0:/*在水平方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y;
dpos.x=1;
dpos.y=0;
break;
case 1:/*在垂直方向*/
pos.x=Cursor.x;
pos.y=Cursor.y-(testnum-1);
dpos.x=0;
dpos.y=1;
break;
case 2:/*在左下至右上的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y+(testnum-1);
dpos.x=1;
dpos.y=-1;
break;
case 3:/*在左上至右下的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y-(testnum-1);
dpos.x=1;
dpos.y=1;
break;
}

count=0;
for(i=0;i<testnum*2+1;i++)
{
if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18)
{
if(gChessBoard[pos.x][pos.y]==Order)
{
count++;
if(count>=testnum)
return TRUE;
}
else
count=0;
}
pos.x+=dpos.x;
pos.y+=dpos.y;
}

return FALSE;
}

/*移動游標*/
void MoveCursor(int Order,int press)
{
switch(press)
{
case PLAY1UP:
if(Order==CHESS1&&gCursor.y>0)
gCursor.y--;
break;
case PLAY1DOWN:
if(Order==CHESS1&&gCursor.y<18)
gCursor.y++;
break;
case PLAY1LEFT:
if(Order==CHESS1&&gCursor.x>0)
gCursor.x--;
break;
case PLAY1RIGHT:
if(Order==CHESS1&&gCursor.x<18)
gCursor.x++;
break;

case PLAY2UP:
if(Order==CHESS2&&gCursor.y>0)
gCursor.y--;
break;
case PLAY2DOWN:
if(Order==CHESS2&&gCursor.y<18)
gCursor.y++;
break;
case PLAY2LEFT:
if(Order==CHESS2&&gCursor.x>0)
gCursor.x--;
break;
case PLAY2RIGHT:
if(Order==CHESS2&&gCursor.x<18)
gCursor.x++;
break;
}

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*游戲結束處理*/
void EndGame(void)
{
textmode(C80);
}

/*顯示當前行棋方*/
void ShowOrderMsg(int Order)
{
gotoxy(6,MAPYOFT+20);
textcolor(LIGHTRED);
if(Order==CHESS1)
cputs("Player1 go!");
else
cputs("Player2 go!");

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*落子正確處理*/
void DoOK(void)
{
sound(500);
delay(70);
sound(600);
delay(50);
sound(1000);
delay(100);
nosound();
}

/*檢查用戶的按鍵類別*/
int CheckKey(int press)
{
if(press==ESCAPE)
return KEYEXIT;/*是退出鍵*/

else
if
( ( press==PLAY1DO && gPlayOrder==CHESS1) ||
( press==PLAY2DO && gPlayOrder==CHESS2)
)
return KEYFALLCHESS;/*是落子鍵*/

else
if
( press==PLAY1UP || press==PLAY1DOWN ||
press==PLAY1LEFT || press==PLAY1RIGHT ||
press==PLAY2UP || press==PLAY2DOWN ||
press==PLAY2LEFT || press==PLAY2RIGHT
)
return KEYMOVECURSOR;/*是游標移動鍵*/

else
return KEYINVALID;/*按鍵無效*/
}