学院首页>图形图像>FLASH>Flash MX 编程深层次应用-网络连线游戏(8)

Flash MX 编程深层次应用-网络连线游戏(8)

作者: 来源: 添加时间:2006-5-23 7:26:12
7.5 实时下棋(2)

 

4.检查哪方胜利的程序

检查哪方胜利的程序如下:

function check_win(row, col, val) {

var i = col, count = 0;

// 先检查行连成四子

while (_root.chess[row][i] == val and i>=0) {

count++;

i--;

}

if (count>=4) {

return true;

}

i = col+1;

while (_root.chess[row][i] == val and i<=6) {

count++;

i++;

}

if (count>=4) {

return true;

}

// 再检查列连成四子

count = 0;

i = row;

while (_root.chess[i][col] == val and i<=5) {

count++;

i++;

}

if (count>=4) {

return true;

}

// 检查左高斜线

count = 0;

i = row;

j = col;

while (_root.chess[i][j] == val and i>=0 and j>=0) {

count++;

i--;

j--;

}

if (count>=4) {

return true;

}

i = row+1;

j = col+1;

while (_root.chess[i][j] == val and i<=5 and j<=6) {

count++;

i++;

j++;

}

if (count>=4) {

return true;

}

// 检查右高斜线

count = 0;

i = row;

j = col;

while (_root.chess[i][j] == val and i>=0 and j<=6) {

count++;

i--;

j++;

}

if (count>=4) {

return true;

}

i = row+1;

j = col-1;

while (_root.chess[i][j] == val and i<=5 and j>=0) {

count++;

i++;

j--;

}

if (count>=4) {

return true;

}

}

站内搜索