精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
返回建站学首页
导航:
建站首页 | 网站设计 | 网站开发 | 网站运营 | 网页软件 | 建站指南 | 搜索优化 | 图像处理 | 视频教程 | 书籍教程 | 建站专题
当前位置:首页>网页软件>FLASH教程>正文

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


来源:站长站 时间:06-09-21 点击: 点击这里收藏本文
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;

    }

}



  把此文章收藏到:          
相关教程
广而告之
文章搜索
  • Google JZxue.Com

关于我们 | 联系我们 | 友情链接 | 网站地图
Copyright © 2005 - 2006 建站学 All rights reserved.