4.检查哪方胜利的程序
检查哪方胜利的程序如下:
function check_win(row, col, val) {
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)var i = col, count = 0;
// 先检查行连成四子
while (_root.chess[row][i] == val and i=0) {
count++;
i--;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)if (count=4) {
return true;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)i = col+1;
while (_root.chess[row][i] == val and i<=6) {
count++;
i++;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)if (count=4) {
return true;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)// 再检查列连成四子
count = 0;
i = row;
while (_root.chess[i][col] == val and i<=5) {
count++;
i++;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)if (count=4) {
return true;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)// 检查左高斜线
count = 0;
i = row;
j = col;
while (_root.chess[i][j] == val and i=0 and j=0) {
count++;
i--;
j--;
}
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/fjc/)if (count=4) {
return true;