中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 图形图象 > 网页设计 > Flash
Flash MX 编程深层次应用-网络连线游戏(7)
作者:未知 时间:2005-05-28 12:12 出处:ChinaZ.com 责编:chinaitpower
              摘要:Flash MX 编程深层次应用-网络连线游戏(7)
7.5 实时下棋(1)

    

7.5.1  实时下棋的子程序

让我们先想想两个人实时下棋需要哪些子程序:

初始化棋盘与棋子
清空棋盘子函数

走棋子程序

检查胜负子程序

1.初始化棋盘与棋子

首先让我们看看前面没有讲的(begin_play)那一帧的内容吧,这一帧实际上就是初始化棋盘与棋子。其程序代码如下:

//棋盘的初始位置

begin_x = 30;

begin_y = 40;

distance = 36;

chessman_number = 1;

//处理当前下棋位置闪烁功能

attachMovie("point", "obj_flash_point", 1000);

_root.obj_flash_point._visible = false;

//和棋、认输、悔棋窗口

attachMovie("windows", "DrawDefeatRepent", 2000);

_root.DrawDefeatRepent._visible = false;

_root.DrawDefeatRepent._x = 150;

_root.DrawDefeatRepent._y = 150;

win_defeat.duplicateMovieClip("obj_win_defeat", 10000);

win_defeat.removeMovieClip();

//表示结果是否已经出来

result = false;

//表示当时在哪个台玩游戏,0表示没有玩

_root.createEmptyMovieClip("chessboard", 1000);

// 产生一个背景方格图

for (i=1; i<=7; i++) {

    // 画模线

    chessboard.lineStyle(1);

    chessboard.moveTo(begin_x, begin_y+(i-1)*distance);

    chessboard.lineTo(begin_x+7*distance, begin_y+(i-1)*distance);

}

for (j=1; j<=8; j++) {

    // 画竖线

    chessboard.moveTo(begin_x+(j-1)*distance, begin_y);

    chessboard.lineTo(begin_x+(j-1)*distance, begin_y+6*distance);

}

for (i=0; i<=6; i++) {

    // 画箭头按钮

    name = "arrow_"+i;

    attachMovie("arrow", name, i+j);

    this[name]._x = begin_x+(i+0.5)*distance;

    this[name]._y = begin_y-distance/2;

    this[name].place = i;

}

//5×7的二维数据来存放棋盘,0表示无棋,1表示我走的棋,2表示对手走的棋

chess = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]];

stop();

//上面代码完成了下棋前的初始化工作

2.清空棋盘函数

清空棋盘函数程序如下:

// 清空程序,在退出下棋时有用

function clear() {

    var i;

    // 清线段

    removeMovieClip(chessboard);

    for (i=0; i<=50; i++) {

             // 清棋子

             name = "chessman_"+i;

             removeMovieClip(name);

    }

    for (i=0; i<=6; i++) {

             // 清箭头

             name = "arrow_"+i;

             removeMovieClip(name);

    }

}

3.走棋子程序

走棋子程序如下:

function runchess(place, name) {

    var i = 5;

    _root.i_run = not _root.i_run;

    _root.obj_flash_point._visible = true;

    if (name == "my") {

             // 我走的棋就放我的棋子

             while (_root.chess[i][place] != 0 and i>=0) {

                      i--;

             }

             if (i>=0) {

                      // 说明棋子下面有子可动

                      _root.chess[i][place] = 1;

                      _root.last_x = i;

                      _root.last_y = place;

                      name = "chessman_"+_root.chessman_number;

                      attachMovie("chessman", name, 100+_root.chessman_number);

                      _root.obj_flash_point._x = this[name]._x=begin_x+(place+0.5)*distance;

                      _root.obj_flash_point._y = this[name]._y=begin_y+(i+0.5)*distance;

                      this[name].gotoAndStop(_root.my_logo);

                      _root.chessman_number++;

                      // 检查是否胜利

                      if (check_win(i, place, 1)) {

                //如果你胜利就跳到你胜利的显示帧

                                _root.obj_win_defeat.gotoAndPlay("you_win");

                                _root.result = true;

                                _root.replay = false;

                                _root.i_can_play = false;

                      } else if (_root.chessman_number>=41) {

                                // 说明已经无棋可走了,成和棋

                                _root.obj_win_defeat.gotoAndPlay("you_draw");

                                _root.result = true;

                                _root.replay = false;

                                _root.i_can_play = false;

                      }

             }

    }

    if (name == "your") {

             // 对方走的棋,就放对方的棋子

             while (_root.chess[i][place] != 0 and i>=0) {

                      i--;

             }

             if (i>=0) {

                      // 说明棋子下面有子可动

                      _root.chess[i][place] = 2;

                      _root.last_x = i;

                      _root.last_y = place;

                      name = "chessman_"+_root.chessman_number;

                      attachMovie("chessman", name, 100+_root.chessman_number);

                      _root.obj_flash_point._x = this[name]._x=begin_x+(place+0.5)*distance;

                      _root.obj_flash_point._y = this[name]._y=begin_y+(i+0.5)*distance;

                      this[name].gotoAndStop(_root.your_logo);

                      _root.chessman_number++;

                      // 检查是否胜利

                      if (check_win(i, place, 2)) {

                //如果对手胜利就等于你输了,跳到你输的显示帧

                                _root.obj_win_defeat.gotoAndPlay("you_defeat");

                                _root.result = true;

                                _root.replay = false;

                                _root.i_can_play = false;

                      } else if (_root.chessman_number>=41) {

                                // 说明已经无棋可走了,成和棋

                 _root.obj_win_defeat.gotoAndPlay("you_draw");

                               _root.result = true;

                                _root.replay = false;

                                _root.i_can_play = false;

                      }

             }

    }

}


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有