資源簡(jiǎn)介
能進(jìn)行簡(jiǎn)單的人機(jī)對(duì)戰(zhàn),有簡(jiǎn)單的圖形界面,添加了圖片

代碼片段和文件信息
#include
#include
#include
#include
#include
typedef?struct?repeal????//悔棋結(jié)構(gòu)體
{
int?x;?????//記錄棋子坐標(biāo)
int?y;
int?type;??//什么顏色的棋子
struct?repeal?*next;
}repeal;
//#pragma?warning(disable:4996)
void?five_menu();??//顯示菜單界面
void?five_qp();??//打印棋盤(pán)
void?five_playgame();?
void?five_AI(int?mychess);???//電腦思考?
int?five_score();???//評(píng)分函數(shù)
void?five_mark(int?xint?yint?countint?angleint?mychess);?????//判斷棋型函數(shù)
int?five_win();???//判斷勝負(fù)
void?add_repeal(int?xint?yint?typerepeal?*L);??
repeal*?init_repeal();???//初始化悔棋鏈表
void?five_repeal();???//悔棋實(shí)現(xiàn)函數(shù)
int?a[23][23]={0};??//15*15的棋盤(pán)(利于后面遍歷棋盤(pán)(4+15+4)*(4+15+4))??[-1012分別代表空,不存在,玩家,電腦]
int?pe[15][15]cp[15][15];??//玩家和電腦計(jì)分?jǐn)?shù)組
int?maxscorepemaxscorecp;?
int?win=0;??//判斷是否勝利(1為玩家勝利2為人機(jī)勝利)
int?play=2;//?默認(rèn)電腦先手
int?win5=0alive4=0die4=0die3=0lowdie4=0alive3=0alive2=0die2=0tiao3=0lowalive2=0other=0;????//活五,活四,死四,死三,低級(jí)死四,活三,活二,跳三,低級(jí)活二,其他
int?count0=1count90=1count45=1count135=1;?//(統(tǒng)計(jì)不同角度四條線連子數(shù))
int?stepcp=0steppe=0;???//統(tǒng)計(jì)步數(shù)
struct?repeal?*RE=init_repeal();
void?main()
{
initgraph(600600);
setbkcolor(BROWN);
five_menu();??//顯示菜單界面
}
repeal*?init_repeal()???//初始化悔棋鏈表
{
repeal?*L;
L=(repeal*)malloc(sizeof(repeal));
if(L==NULL)
exit(0);
L->next=NULL;
return?L;
}
void?add_repeal(int?xint?yint?typerepeal?*L)???//添加節(jié)點(diǎn)(采用帶頭結(jié)點(diǎn)的頭插入)
{
struct?repeal?*p;
p=(repeal*)malloc(sizeof(repeal));
p->x=x;
p->y=y;
p->type=type;
p->next=L->next;
L->next=p;
}
void?five_repeal()???//悔棋實(shí)現(xiàn)函數(shù)
{
repeal?*L;
L=(repeal*)malloc(sizeof(repeal));
if(L==NULL)
exit(0);
L=RE->next;
if(L!=NULL&&L->next!=NULL)
{
for(int?i=0;i<2;i++)
{
setfillcolor(BROWN);??//背景填充????
????????????solidcircle(L->xL->y10);??//覆蓋
a[(L->x-50)/30+4][(L->y-50)/30+4]=-1;
setlinecolor(YELLOW);
line(L->x-10L->yL->x+10L->y);
line(L->xL->y-10L->xL->y+10);
L=L->next;??//指針后移
Sleep(500);
}
stepcp--;???
steppe--;
RE->next=L;
}
}
void?five_menu()??//顯示菜單界面
{
IMAGE?img;????//定義圖像變量
loadimage(&img“1.jpg“600600);
putimage(00&img);
settextstyle(5020“宋體“);
outtextxy(200400“開(kāi)始游戲“);
MOUSEMSG?m;
while(true)
{
m=GetMouseMsg();
if(m.uMsg==WM_MOUSEMOVE&&m.x>=200&&m.x<=360&&m.y>=400&&m.y<=450)
{
setlinecolor(YELLOW);
rectangle(200400360450);
}
if(m.uMsg==WM_LBUTTONDOWN&&m.x>=200&&m.x<=360&&m.y>=400&&m.y<=450)
{
cleardevice();??//清除視圖
Sleep(500);
five_qp();??????//棋盤(pán)界面函數(shù)
break;
}
if(!(m.x>=200&&m.x<=360&&m.y>=400&&m.y<=450))??//當(dāng)鼠標(biāo)移開(kāi)時(shí)覆蓋掉上一條的黃色邊框
{
setlinecolor(BLACK);
rectangle(200400360450);
}
}
}
void?five_qp()??//打印棋盤(pán)
{
setlinecolor(YELLOW);
for?(int?i?=?50;?i?<=?470;?i?+=?30)
{
???????line(i?50?i?470);
???????line(50?i?470?i);
}
settextstyle(1610“宋體“);
outtextxy(50050“電腦步數(shù):“);
outtextxy(500420“玩家步數(shù):“);
outtextxy(520200“新游戲“);
outtext
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????156102??2019-01-24?10:59??五子棋\1.jpg
?????文件???????33707??2019-01-26?21:11??五子棋\五子棋.cpp
評(píng)論
共有 條評(píng)論