Flash游戏制作--五子连珠(二)

// 显示棋子
_root.display = "Xpos : " + (x + 1);
temp = chr ( y + 65);
_root.display1 = "Ypos : " + temp;
_root.playnow = "player";
//判断是否获胜
xx = x;
yy = y;
for (k=0; k 6) {
_root.a_result = 0;
x = xx;
y = yy;
while ((_root.table[y][x] == 2) and (y+_root.dir[k][1] = -1) and (x+_root.dir[k][0] = -1)) {
x = x + _root.dir[k][0];
y = y + _root.dir[k][1];
// "_root.table["+y+"]["+x+"]="+_root.table[y][x]
_root.a_result = _root.a_result+1;
}
x = xx;
y = yy;
while ((_root.table[y][x] == 2) and (y+_root.dir[k+4][1] = -1) and (x+_root.dir[k+4][0] = -1)) {
x = x + _root.dir[k+4][0];
y = y + _root.dir[k+4][1];
_root.a_result = _root.a_result+1;
}
if (_root.a_result == 6) {
_root.playnow = "nobody";
}
}
}
if (_root.playnow =="nobody") {
_root.gameoverman.gotoAndPlay(2);
}
}
C:新建一个Movie clip组件,并命名为bb,此组件用来计算电脑如何走棋,进入组件编辑状态后,在图层layer1绘制一个有填充色的矩形,然后在第5桢插入一个关键桢,在同样位置绘制一个大小相同填充色不同的矩形。新建一个图层,在矩形里输入提示文字:电脑走棋,然后再新建一个图层Action,在第一桢添加AS: stop();,在第8桢插入一个关键桢,在此桢添加如下AS:
if (_root.playnow == "computer") {
//初始化棋盘
_root.func.makelist("white");
_root.func.makelist("black");
//调用自定义函数
max_computer = 0;
max_player = 0;
k = 0;
//定义三变量
for (j=0; j 50) {
max_computer = _root.computer[j*15+i][k] ;
xc = i;
yc = j;
}
}
if (_root.computer[j*15+i][k] > max_computer) {
max_computer = _root.computer[j*15+i][k] ;
xc = i;
yc = j;
}
if (_root.player[j*15+i][k] > max_player) {
max_player = _root.player[j*15+i][k] ;
xp = i;
yp = j;
}
}
}
}
if (max_computer > max_player) {
x = xc;
y = yc;
} else {
x = xp;
y = yp;
}
// 绘制棋子
num = y * 15 + x;
removeMovieClip(_root.b add num);
duplicateMovieClip(_root.white, "white" add num, num + 300);
setProperty(_root.white add num, _x, 34.7 + x * 20);
setProperty(_root.white add num, _y, 34.7 + y * 20);
_root.table[y][x] = 2;
// 显示棋子
_root.display = "Xpos : " + (x + 1);
temp = chr ( y + 65);
_root.display1 = "Ypos : " + temp;
_root.playnow = "player";
// 判断是否获胜
xx = x;
yy = y;
for (k=0; k 6) {
_root.a_result = 0;
x = xx;
y = yy;
while ((_root.table[y][x] == 2) and (y+_root.dir[k][1] = -1) and (x+_root.dir[k][0] = -1)) {
x = x + _root.dir[k][0];
y = y + _root.dir[k][1];
// "_root.table["+y+"]["+x+"]="+_root.table[y][x]
_root.a_result = _root.a_result+1;
}
x = xx;
y = yy;
while ((_root.table[y][x] == 2) and (y+_root.dir[k+4][1] = -1) and (x+_root.dir[k+4][0] = -1)) {
x = x + _root.dir[k+4][0];
y = y + _root.dir[k+4][1];
_root.a_result = _root.a_result+1;
}
 
if (_root.a_result == 6) {
_root.playnow = "nobody";
}
}
}
// 游戏结束
if (_root.playnow =="nobody") {
_root.gameoverman.gotoAndPlay(2);
}
}
最后的时间线如图6所示:
[img]http://www.flasherclub.com/Picture/Tutorial/20051217/2005121721063191.jpg[/img]
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/797.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值