C語言版五子棋

2021-06-28 20:59:29 字數 2136 閱讀 9299

#include "windows.h"

#include #include #include #ifndef __cplusplus

#include /*包含bool、false */

#endif //__cplusplus

/*****************************************/

#define board 16

coord g_chesspos=; /*儲存游標位置*/

short g_chessinfo[board][board]; /*g_chessinfo儲存棋局資訊,白子置為1,黑子為2,空則為0*/

/*****************************************/

void map(void); //繪製棋盤

void gotoxy(short,short);

void down(short,short); //落子

void play(int);

void run(void);

void showcursor(void); //顯示游標

void clscursor(void); //清除游標

void mark(int) ; //標記黑子或白子

void printinfo(void); //輸出資訊

bool isempty(void); //有棋子則為false

bool iswin(int); /*判斷是否獲勝,true為獲勝,int引數為1白子 ,2為黑子*/

/*****************************************/

int main(int argc, char *argv) ; //隱藏游標

setconsolecursorinfo(getstdhandle(std_output_handle), &cursor_info);

printinfo();

map();

showcursor();

run();

down(g_chesspos.x,g_chesspos.y);

system("pause");

return 0;

} void gotoxy(short x,short y)

; setconsolecursorposition(s_hconsole,coord);

}void map(void)

} /*清除棋盤多餘部分*/

for(y=2;y<=32;y+=2)

for(x=10;x<=70;x+=4) }

void printinfo(void)

void down(short x,short y)

gotoxy(76,16);printf("執黑子");

} else

gotoxy(76,16);printf("執白子");

} who++;

}void run(void)

bool isempty(void)

void mark(int i)

void play(int c)

showcursor();

}void showcursor(void)

void clscursor(void)

if(g_chesspos.y!=32) }

bool iswin(int t)

if(num>=5) return true;

/ i=x;j=y;num=0; //縱向向下

while(j=0&&t==g_chessinfo[i][j])

if(num>=5) return true;

/ i=x;j=y;num=0; //左斜向下

while(i=0&&j>=0&&t==g_chessinfo[i][j])

if(num>=5) return true;

i=x;j=y;num=0; //右斜向下

while(i>=0&&j=0&&i=5) return true;

return false;

}

五子棋之c語言版

實現五子棋版本 define crt secure no warnings include include include define row 10 define col 10 char border row col int play row 0 int play col 0 用來記錄玩家和電腦最...

C語言五子棋

實戰五子棋 思路 1.棋盤由邊緣數字和橫豎線及棋子構成 2.先init初始化,畫出棋盤的數字邊緣,為了第一次下棋的時候能看見棋盤樣子,其實可以封裝起來用 3.落子之後呼叫draw cross畫出整個棋盤,依舊是先畫邊緣數字,再畫棋子,一行一行畫 4.判斷輸贏。include include defi...

五子棋(C語言)

問題描述 在乙個10 10的棋盤中進行人機對戰 在這之前寫了一篇三子棋的 五子棋與其原理相似,主要區別在於判斷輸贏上,10 10的棋盤,贏的條件是每行,每列,或正反對角線上有五個連續相同的棋子。標頭檔案 fivechess.h ifndef fivechess h define fivechess ...