[c]代码库
#include"global.h"
#include"game.h"
#include"modal.h"
int AnChessStatus[15][15];
void initStatus()
{
int i;
int j;
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
AnChessStatus[i][j]=STATUS_BLANK;
}
}
}
int getStatus(const Point spPoint)
{
return AnChessStatus[spPoint.row][spPoint.col];
}
void setStatus(const Point spPoint)
{
AnChessStatus[spPoint.row][spPoint.col]=spPoint.status;
}
int judge(Point spPoint)
{
int count=0;
spPoint.status=AnChessStatus[spPoint.row][spPoint.col];
//横向
count=judgeHorizontal(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
//竖向
count=judgeVertical(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
//向上对角线
count=judgeHyperphoria(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
//向下对角线
count=judgeHypophoria(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
if(judgeDraw()==TRUE)
{
return JUDGE_DRAW;
}
return JUDGE_PLAY;
}
//横向
int judgeHorizontal(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row;
while(j>=0)
{
if(AnChessStatus[i][j--]==standard)
{
counter++;
}
else
{
break;
}
}
j=spPoint.col+1;
while(j<=14)
{
if(AnChessStatus[i][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}
//竖向
int judgeVertical(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col;
i=spPoint.row-1;
while(i>=0)
{
if(AnChessStatus[i--][j]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row+1;
while(i<=14)
{
if(AnChessStatus[i++][j]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}
//向上对角线
int judgeHyperphoria(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row+1;
while(i>=0&&j>=0)
{
if(AnChessStatus[i++][j--]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row-1;
j=spPoint.col+1;
while(i<=14&&j<=14)
{
if(AnChessStatus[i--][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}
//向下对角线
int judgeHypophoria(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row-1;
while(i>=0&&j>=0)
{
if(AnChessStatus[i--][j--]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row+1;
j=spPoint.col+1;
while(i<=14&&j<=14)
{
if(AnChessStatus[i++][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}
int judgeDraw()
{
int i;
int j;
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
if(AnChessStatus[i][j]==STATUS_BLANK)
{
return FALSE;
}
}
}
return TRUE;
}
[源代码打包下载]
by: 发表于:2017-06-20 16:11:24 顶(0) | 踩(0) 回复
??
回复评论