首 页 ┆ 源码下载 ┆ IT学院 ┆ 字体下载 ┆ 模板下载 ┆ 源码发布 ┆ 广告合作 ┆ 网站地图 ┆ 虚拟主机 ┆ 中文域名
► 设为首页
► 加入收藏
► 联系我们
源码下载 >> ASP源码 | PHP源码 | ASP.net源码 | JSP源码 | CGI源码 | VC/C++源码 | VB源码 | Delphi源码 | Flash源码
文章学院 >> 网络编程 | 网页设计 | 图形图象 | 数据库 | 服务器 | 网络媒体 | 网络安全 | 操作系统 | 办公软件 | 软件开发 | 黑客知识
字体下载 >> 精制字体 | 非英字体 | 艺术字体 | 著名字体 | 哥特式 | 简单字体 | 手写体 | 节假日 | 图案字体 | 精度像素 | 中文字体
模板下载 >> 企业门户 | 数码网络 | 休闲娱乐 | 影视音乐 | 旅游名胜 | 文化艺术 | 电子商务 | 个性展示 | 登陆导航 | Flash模板
►►您当前的位置:源码园 → IT学院 → 网络媒体 → FLASH → 文章内容

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

作者:风未起时  来源:中国站长学院  发布时间:2007-2-8 0:34:29
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;

                      }

             }

    }

}



[] [返回上一页] [打 印]
  • 上一篇文章:Flash MX 编程深层次应用-网络连线游戏(6)
  • 下一篇文章:Flash MX 编程深层次应用-网络连线游戏(8)

  • 相关文章:
  • Flash中if条件语句的用法
  • [组图]教你利用Flash制作梦幻仙境效果
  • [组图]用Flash制作简单光晕效果的
  • flash菜单与asp.net进行交互
  • Delphi让你发送Flash电子邮件(2)
  • Delphi让你发送Flash电子邮件(1)
  • Delphi让你发送Flash电子邮件
  • Delphi的两个实用技巧(1)播放Flash
  • 类似于FlashGet的悬浮框的制作
  • 让Word也来播放Flash动画
  • [图文]把Word文件转换成Flash
  • 基于S3C4510B的系统的Flash擦除与烧写问题(一)
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 源码发布
Copyright © 2003-2009 Ymyasp.Com. All Rights Reserved .
备案序号:粤ICP备07029071号