longchao9527 于 2014.03.16 10:51 提问

public boolean isWon(int posX,int posY){
int sameCount=0;
int startX=0;
int startY=0;
int endX=BOARD_SIZE-1;
int endY=endX;
int tmp=0;

``````    tmp=posX-4;
startX=tmp<0?0:tmp;

tmp=posY-4;
startY=tmp<0?0:tmp;

tmp=posX+4;
endX=tmp>BOARD_SIZE-1?BOARD_SIZE-1:tmp;

tmp=posY+4;
endY=tmp>BOARD_SIZE-1?BOARD_SIZE-1:tmp;

//纵向扫描黑子
for(int i=startY;i<endY;i++){
if(board[posX][i]=="●"&&board[posX][i+1]=="●"){
sameCount++;
}else if(sameCount>=4){
System.out.println("黑子赢！");
sameCount=0;
return true;
}else if (board[posX][i]=="●"&&board[posX][i+1]!="●") {
sameCount=0;
}
}

//横向扫描黑子
for(int i=startX;i<endX;i++){
if(board[i][posY]=="●"&&board[i+1][posY]=="●"){
sameCount++;
}else if(sameCount>=4){
System.out.println("黑子赢！");
sameCount=0;
return true;
}else if (board[i][posY]=="●"&&board[i+1][posY]!="●") {
sameCount=0;
}
}

//斜方向扫描黑子

for(int i=startX,j=startY;i<endX&&j<endY;i++,j++){
if(board[i][j]=="●"&&board[i+1][j+1]=="●"){
sameCount++;
}else if(sameCount>=4){
System.out.println("黑子赢！");
sameCount=0;
return true;
}else if (board[i][j]=="●"&&board[i+1][j+1]!="●") {
sameCount=0;
}
}
``````