// 顯示棋子
_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所示:
本文轉自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/797.html
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
