FLASH教程:as3实现的俄罗斯方块
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-07
|
Live():void {
var r:Number = Math.random();
if (r < 0.2) {
lives[lives[0]] = 0;
liveBoxs[0]={ x:1, y:0 } ;
liveBoxs[1]={ x:0, y:0} ;
liveBoxs[2]={ x:2, y:0 } ;
liveBoxs[3] = { x:3, y:0 } ;
}else if (r < 0.4) {
lives[lives[0]] = 1;
liveBoxs[0]={ x:1, y:0 } ;
liveBoxs[1]={ x:0, y:0} ;
liveBoxs[2]={ x:1, y:1 } ;
liveBoxs[3]={ x:2, y:1 } ;
}else if (r < 0.6) {
lives[lives[0]] = 2;
liveBoxs[0]={ x:1, y:0 } ;
liveBoxs[1]={ x:0, y:1} ;
liveBoxs[2]={ x:1, y:1 } ;
liveBoxs[3]={ x:2, y:0 } ;
}else if (r < 0.8) {
lives[lives[0]] = 3;
liveBoxs[0]={ x:0, y:0 } ;
liveBoxs[1]={ x:0, y:1} ;
liveBoxs[2]={ x:1, y:1 } ;
liveBoxs[3]={ x:1, y:0 } ;
}else {
lives[lives[0]] = 4;
liveBoxs[0]={ x:1, y:1 } ;
liveBoxs[1]={ x:1, y:0} ;
liveBoxs[2]={ x:0, y:1 } ;
liveBoxs[3]={ x:2, y:1 } ;
}
move((int)(xNum / 2), 1);
if (lives[0] == livesLength) {
lives[0] = 1;
}else {
lives[0]++;
}
}
private function liveToDead():void {
for (var i:int = 0; i < liveBoxs.length; i++) {
deadBoxs[liveBoxs.y][liveBoxs.x] = 1;
}
}
private function clear():void {
for (var i:int = 0; i < yNum; i++ ) {
var counter:int = 0;
for (var j:int = 0; j < xNum;j++ ) {
if (deadBoxs[j] != 1) {
break;
}
counter++;
}
if (counter==xNum) {
for (j = 0; j < xNum;j++ ) {
deadBoxs[j] = 0;
}
for (var ii:int = i; ii > 0;ii-- ) {
for (j = 0; j < xNum;j++ ) {
deadBoxs[ii][j] = deadBoxs[ii-1][j];
}
}
for (j = 0; j < xNum;j++ ) {
deadBoxs[0][j] = 0;
}
}
}
}
private function isBottom():Boolean {
var ret:Boolean = false;
for (var i:int = 0; i < liveBoxs.length;i++ ) {
if (liveBoxs.y ==yNum-1) {
ret = true;
break
}
for (var ii:int = 0; ii < yNum; ii++ ) {
for (var j:int = 0; j < xNum; j++ ) {
if ((deadBoxs[ii][j]==1)&&(liveBoxs.y==ii-1)&&(liveBoxs.x==j)) {
ret = true;
break
}
}
}
}
return ret;
}
private function isLive():Boolean {
var ret:Boolean = true;
for (var i:int = 0; i < liveBoxs.length;i++ ) {
if (
(liveBoxs.x < 0)
||(liveBoxs.x> ( xNum - 1))
||(liveBoxs.y < 0)
||(liveBoxs.y>(yNum-1))
) {
ret = false;
break
}
for (var ii:int = 0; ii < yNum; ii++ ) {
for (var j:int = 0; j < xNum; j++ ) {
if ((deadBoxs[ii][j]==1)&&(liveBoxs.x==j)&&(liveBoxs.y==ii)) {
ret = false;
break
}
}
}
}
return ret;
}
private function move(x:int=1, y:int |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|