快速业务通道

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

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-10

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) { ?????????????????

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号