0面向目的游戏支付,达成俄罗丝方块

正文转自:http://www.alixixi.com/Dev/W3C/Flash/2007/2007070868666.html

[html]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt
<html xmlns=”http://www.w3.org/1999/xhtml"&gt
<head> 
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″
/> 
<title>俄罗斯方块</title> 
<style type=”text/css”> 
    body{ width:530px; background:#F7F7F7; margin:20px auto} 
    table#gameBoard{ border:1px solid black; border-collapse: collapse;
float:left;} 
    table#gameBoard td{ width:30px; height:30px; border: 1px dotted
#0cc;} 
    div#gameControl{ widows:160; float:right; height: 200px;;
line-height: 200px;} 
    .font{ font-family:’微软雅黑’; font-size:18px;
text-align:center;} 
    div input { width: 60px; height:25px; } 
 
</style> 
<script type=”text/javascript”> 
     
 
    var T = TETRIS = { 
        aBoardGrids : [], 
        aShapes: [ 
            [0xCC00],  
            [0x8888, 0xF00],  
            [0x8C40, 0x6C00],  
            [0x4C80, 0xC600],  
            [0x44C0, 0x8E00, 0xC880, 0xE200],  
            [0x88C0, 0xE800, 0xC440, 0x2E00],  
            [0x4E00, 0x8C80, 0xE400, 0x4C40] 
       
],                                                                     
//代表全数方块的形制数 
        init : function(){ 
            this.oDomBoard = document.getElementById(“gameBoard”); 
            this.oDomScore = document.getElementById(“score”); 
            this.aBoardGrids = new Array(18); 
            for (var rows = 0 ; rows < 18 ; rows++){ 
                this.aBoardGrids[rows] = new Array(10); 
                var oDomTr = this.oDomBoard.insertRow(-1); 
                for (var cols = 0 ; cols < 10 ; cols++){ 
                    this.aBoardGrids[rows][cols] = 0; 
                    oDomTr.insertCell(cols); 
                } 
            } 
 
            document.onkeydown = function(keyEvent){ 
                keyEvent = keyEvent || window.event; 
                var ikeyNum = keyEvent.which || keyEvent.keyCode; 
                switch(ikeyNum){ 
                    case 37://← 
                        T.oBlock.move(“left”); 
                        break; 
                    case 38://↑  
                        T.oBlock.rotate((function (){ 
                            var vShape      = T.aShapes[T.iShapeIdx][
(++T.index)%T.aShapes[T.iShapeIdx].length]; 
                            var sShape      =
vShape.toString(2);                                
                            sShape          = new Array(17 –
sShape.length).join(0) + sShape;    
                            T.matrix        =
sShape.match(/\d{4}/g);    
                            return T.matrix; 
                        })());  //变形 
                        break; 
                    case 39://→ 
                        T.oBlock.move(“right”); 
                        break; 
                    case 40://↓ 
                        T.oBlock.move(“down”); 
                        break; 
                } 
            } 
        }, 
        next : function (){ 
             
            this.iShapeIdx  = parseInt(Math.random() *
this.aShapes.length); 
            this.index      = 0; 
            var vShape      =
this.aShapes[this.iShapeIdx][this.index]; 
            var sShape      =
vShape.toString(2);                              
//将16进制调换为二进制 
            sShape          = new Array(17 – sShape.length).join(0) +
sShape;   //缺乏十六位,在前边用0补全  
            this.matrix     =
sShape.match(/\d{4}/g);                          
//利用正则表明式匹配 
 
            this.oBlock = new TETRIS.Block(this.matrix); 
                     
            clearInterval(T.timer); 
            //注册电火花计时器 
            T.timer = setInterval(function (){ 
                T.oBlock.move(“down”); 
            }, 1000); 
             
             
            if( !T.oBlock.checkBlock() ){ 
                alert(“Game Over~”); 
                clearInterval(T.timer); 
             
            } 
             
        }, 
        updateBoard : function (){      //更新面板 
            for(var i = 0 ; i < 4 ; i++){ 
               
this.aBoardGrids[T.oBlock.shape[i].y][T.oBlock.shape[i].x] =
1; 
            } 
        }, 
        eraseLines : function (){ 
            var iLines = 0; 
            for(var j = 17 ; j >= 0 ; j–){ 
                var num = 0; 
                for(var i = 0 ; i< 10 ; i++){ 
                    if(this.aBoardGrids[j][i] == 1) 
                        num ++; 
                } 
                if(num == 10){ 
                    iLines ++; 
                    for(var m = 0 ; m < i ; m++){ 
                        for(var n = j ; n > 0 ; n–){ 
                            this.aBoardGrids[n][m] =
this.aBoardGrids[n-1][m]; 
                           
T.oDomBoard.rows[n].cells[m].style.background =
T.oDomBoard.rows[n-1].cells[m].style.background; 
                        } 
                        this.aBoardGrids[0][m] = 0; 
                    } 
                    j++; 
                } 
            } 
            return iLines; 
        }, 
        setScore : function (iLines){ 
            var iScore = parseInt(this.oDomScore.innerHTML); 
            if(iLines == 1){ 
                iScore += 100; 
            } else if(iLines == 2){ 
                iScore += 300; 
            } else if(iLines == 3){ 
                iScore += 500; 
            } else if(iLines == 4){ 
                iScore += 1000; 
            } 
            this.oDomScore.innerHTML = iScore; 
        } 
    } 
     
    TETRIS.Block = function (matrix){ 
 
        this.shape = (function(){ 
             
            var aShape = []; 
            for(var i = 0 ; i < matrix.length ; i++){ 
                var sValue = matrix[i]; 
                for(var j = 0 ; j < sValue.length ; j++){ 
                    if(sValue.charAt(j) == “1”){ 
                        aShape.push({ x : j+3 , y : i }); 
                    }   
                } 
            } 
             
            return aShape; 
             
        })(); 
        this.draw(); 
    } 
     
    TETRIS.Block.prototype.move = function (direction){//移动 
        if(this.checkBlock(this.shape,direction)){ 
            this.draw(“clear”); 
            for(var i = 0 ; i < 4 ; i++){ 
                switch(direction){ 
                    case “left”://←  
                        this.shape[i].x–; 
                        break; 
                    case “right”: 
                        this.shape[i].x++; 
                        break; 
                    case “down”: 
                        this.shape[i].y++; 
                        break; 
                } 
            } 
            this.draw(); 
        } else { 
            if(direction == “down”){ 
                this.draw(); 
                T.updateBoard();    //更新面板 
                var iLines = T.eraseLines(); 
                 
                if(iLines > 0){ 
                 
                    T.setScore(iLines); 
                     
                } 
                 
                T.next();           //再生成一个新的方块 
            } 
        } 
         
    } 
    TETRIS.Block.prototype.rotate = function (matrix){//变形 
         
        this.shape = (function(oBlock){ 
             
            var aX = []; 
            var aY = []; 
 
            for(var i = 0 ; i < 4 ; i++){ 
                aX.push(oBlock.shape[i].x); 
                aY.push(oBlock.shape[i].y); 
            } 
            var iMinX = aX.getMin(); 
            var iMinY = aY.getMin(); 
             
             
            var aShape = []; 
            for(var i = 0 ; i < matrix.length ; i++){ 
                var sValue = matrix[i]; 
                for(var j = 0 ; j < sValue.length ; j++){ 
                    if(sValue.charAt(j) == “1”){ 
                        aShape.push({ x : j+iMinX , y : i+iMinY }); 
                    }   
                } 
            } 
            if( !( oBlock.checkBlock(aShape)) ) 
                return oBlock.shape; 
            oBlock.draw(“clear”); 
            return aShape; 
             
        })(this); 
 
        this.draw(); 
    } 
 
    TETRIS.Block.prototype.draw = function (opt){//绘图 
        for(var i = 0 ; i < this.shape.length ; i++){ 
            var oShape = this.shape[i]; 
           
T.oDomBoard.rows[oShape.y].cells[oShape.x].style.background =
(opt==undefined?”#09F”:””); 
        } 
    } 
    TETRIS.Block.prototype.checkBlock = function (shape, direction){ 
        shape = shape || this.shape; 
        for(var i = 0 ; i < 4 ; i++){ 
            if(direction == “left”){ 
                    if(shape[i].x == 0 ||
T.aBoardGrids[shape[i].y][shape[i].x – 1] == 1){ 
                        return false; 
                    } 
            } else if(direction == “right”){ 
                    if(shape[i].x == 9 ||
T.aBoardGrids[shape[i].y][shape[i].x + 1] == 1){ 
                        return false; 
                    } 
            } else if(direction == “down”){ 
                    if(shape[i].y == 17 || T.aBoardGrids[shape[i].y

概述:

Flash
ActionScript2.0是一种面向对向的编制程序语言,利用它能够支付出功用壮大的施用程序.以开始的一段时代的ActionScript
1.0对照,它在结构化编制程序上全数鲜明的优势,能够使程序有所越来越强的可移植性,可重性,和伸缩性.

本文通过二个推箱子游戏的开销进程来稳步陈诉怎么样采用ActionScript2.0
进行开辟.

  • 1][shape[i].x] ==1){ 
                            return false; 
                        } 
                } 
                if(shape[i].x < 0 || shape[i].x > 9 ||
    shape[i].y < 0 || shape[i].y > 17) 
                    return false; 
                if(T.aBoardGrids[shape[i].y][shape[i].x] == 1){ 
                    return false; 
                } 
            } 
            return true; 
             
        } 
        Array.prototype.getMin = function (){ 
            var iMin = this[0]; 
            for(var i = 0 ; i < this.length ; i++){ 
                if(this[i] < iMin) 
                    iMin = this[i]; 
            } 
            return iMin; 
        } 
        window.onload = function(){ 
         
            T.init(); 
             
            var oBtnPlay = document.getElementById(“btnPlay”); 
            oBtnPlay.onclick = function(){ 
                if(this.value == “begin”){ 
                    T.next(); 
                    this.value = “over”; 
                } else { 
                    this.value = “begin”; 
                    alert(“Game Over~”); 
                    clearInterval(T.timer); 
                }  
             
            }    
            var oBtnPause = document.getElementById(“btnPause”); 
            oBtnPause.onclick = function (){ 
                if(this.value == “pause”){ 
                    clearInterval(T.timer); 
                    this.value = “resume”; 
                } else { 
                    T.timer = setInterval(function (){ 
                        T.oBlock.move(“down”); 
                    }, 1000); 
                    this.value = “pause”; 
                } 
            } 
     
        } 
     
    </script> 
    </head> 
     
    <body> 
        <table id=”gameBoard”></table> 
        <div id=”gameControl”> 
            Score : <span id=”score”>0</span><br /> 
          <input type=”button” id=”btnPlay” value=”begin” /> 
          <input type=”button” id=”btnPause” value=”pause”
    /><br/> 
            <span>俄罗丝四方</span> 
        </div> 
    </body> 
    </html> 
    作者:zhang__bing

组织剖判:

在开始展览一个档期的顺序的支出前,项目规化是少不了的.大家先来想想一下推箱子游戏包涵哪些必要的因素呢?

  • 一个玩家(Player)
  • 至少三个箱子(Box)
  • 和箱子数目同样的目标地(Target)
  • 数目不定的砖块(Brick)
  • 砖块连在一下组合了墙壁(Wall)
  • 多个游乐管理者(Manager)
  • 一部分展现游戏音信的控件

大家都亟需将那个要素抽象化为指标(Object),种种对象涵盖有独家特有的性子和方法.例如,游戏发烧友全部地方属性(currentPos),它表示游戏发烧友当全的职位,游戏发烧友还应该有move方法,它使游戏的使用者移到下贰个地方.等腰三角形那个主题素材搞掌握了,大家将在开始展览具体的达成.

http://www.bkjia.com/Javascript/506630.htmlwww.bkjia.comtruehttp://www.bkjia.com/Javascript/506630.htmlTechArticle\[html\] !DOCTYPE html PUBLIC -//W3C//DTD XHTML
1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html
xmlns=http://www.w3.org/1999/xhtml head meta http-equ…

金镶玉裹福禄双全进度:

  1. 开发Flash,新建”动作脚本文件”,依次构建如下.as文件,注意要把它们位于同贰个目录下.源文件如下:
  2. //*********Pos.as*********
    //用来表示游戏中物体地方的类 //游戏中兼有目的的职务都为此类的实例
    //用col,row 多少个量分明物体的地点 class Pos { var col:Number;// 列值
    var row:Number;// 行值
    //构造函数 function Pos(c, r) { col = c; row = r; }
    //判别四个职位是否重合 function equals(t):Boolean { return (col ==
    t.col && row == t.row); }
    //依据方向值,获得此岗位的下八个岗位 function getNextPos(d):Pos{ var
    nextPos:Pos; nextPos=new Pos(col,row); switch (d) { case 0 :
    nextPos.col++;
    break; case 1 : nextPos.row++; break; case 2 : nextPos.col–; break;
    case 3 : nextPos.row–; break; } return nextPos; } }
  3. //************Wall.as************
    //用来构建游戏中的墙壁 class Wall extends MovieClip { var
    brickMatrix:Array;//表示墙壁形状的数组 var left:Number;//左偏移量
    var top:Number;//上偏移量 var
    bricks:Array;//用来存放砖块电影剪辑的数组 var
    _stepSize:Number;//每块砖的偏移量
    //构造函数 function Wall() { left = 0; top = 0; _stepSize = 40;
    }
    //设置墙壁形状数组 function setMatrix(b) {
    bricks = new Array(); brickMatrix = b; }
    //依据墙壁形状数组修墙 function build():Void { var index = 0; for
    (var i = 0; i<brickMatrix.length; i++) { for (var j = 0;
    j<brickMatrix[0].length; j++) { if (brickMatrix[i][j] == 1)
    { //数组值为1,画一块砖 bricks[index] = attachMovie(“Brick”,
    “bricks”+index, this.getNextHighestDepth()); bricks[index]._x =
    left+j*_stepSize; bricks[index]._y = top+i*_stepSize;
    index++; } } } } }
  4. //*************Target.as*****************
    class Target extends MovieClip{ var pos:Pos; var finished:Boolean;
    var left:Number; var top:Number; var _stepSize:Number; function
    Target(){ finished=false; left=0; top=0; _stepSize=40;
    } function setPos(p){ pos=p; this._x=left+pos.col*_stepSize;
    this._y=top+pos.row*_stepSize; } }
  5. //*************Player.as**************
    //游戏中的player class Player extends MovieClip {

    var _stepSize:Number;//步长 var _wall:MovieClip;//墙壁电影剪彩辑
    var startPos:Pos;//开始置 var currentPos:Pos;//当前职责 var
    left:Number;//左边距 var top:Number;//下面距 var
    dir:Number;//移动方向 var boxes:Array; var
    player_path_stack:Array;//游戏者移动的路径 var
    boxes_path_stack:Array;//箱子移动的不二秘技
    //构造函数,初叶化 function Player() { _stepSize = 40; currentPos =
    null; left = 0; top = 0; dir = 0; player_path_stack=new Array();
    boxes_path_stack=new Array();
    boxes = new Array(); }
    //设置游戏发烧友的序幕地方 function setStartPos(p) { startPos = new
    Pos(p.col, p.row); currentPos = startPos; this._x =
    currentPos.col*_stepSize+left; this._y =
    currentPos.row*_stepSize+top;

    }
    //为游戏发烧友钦命三个wall实例 function setWall(w) { _wall = w; }
    //为游戏的使用者钦命一个boxes数组,存有全数的箱子实例 function set博克斯es(b) {
    boxes = b; }
    //通过按钮调节游戏的使用者 function setKeyHandle() { this.onKeyDown =
    function() {
    if (Key.isDown(Key.LEFT)) { dir = 2;//左键
    } else if (Key.isDown(Key.RIGHT)) { dir = 0;//右键
    } else if (Key.isDown(Key.UP)) { dir = 3;//上键
    } else if (Key.isDown(Key.DOWN)) { dir = 1;//下键
    } var nextObject = this.getNextObject();
    //取得游戏发烧友下三个职位上的物体
    if (nextObject == “BOX”) { //游戏发烧友下三个任务上是个箱子 var
    box_pushed = getPushedBox();//获得此岗位上的那一个箱子
    //被推到的箱子存在 if (box_pushed) {
    if (box_pushed.getNextObject() == “NOTHING”)
    {//被推箱子的下个职位并未有阻力
    boxes_path_stack.push({box:box_pushed,pos:new
    Pos(box_pushed.pos.col,box_pushed.pos.row)});
    box_pushed.move();//被推箱子移一步 this.move();//游戏发烧友移一步
    }
    }
    } else if (nextObject == “NOTHING”) {//游戏者的下个职位玩障碍
    this.move(); boxes_path_stack.push(null); }
    }; Key.addListener(this); //监听按钮输入 }

    //获得被推到的箱子 function getPushedBox() { var nextPos:Pos;
    nextPos =currentPos.getNextPos(dir);
    for (var i = 0; i<boxes.length; i++) { if
    (boxes[i].pos.equals(nextPos)) { return boxes[i]; break;
    //trace(box_pushed); } } return null; }
    //猎取游戏的使用者下个岗位上的物块类型( 墙壁, 箱子, 无障碍) function
    getNextObject():String { //var obj:String; var nextPos:Pos; nextPos
    = currentPos.getNextPos(dir);
    if (_wall.brickMatrix[nextPos.row][nextPos.col] == 1) { return
    “WALL”; } for (var i = 0; i<boxes.length; i++) { if
    (boxes[i].pos.equals(nextPos)) { return “BOX”; } } return
    “NOTHING”; }
    //移到下个职分 function move() {
    player_path_stack.push(currentPos);
    var c=currentPos.getNextPos(dir); currentPos=c; this._x =
    left+this.currentPos.col*_stepSize; this._y =
    top+this.currentPos.row*_stepSize;
    }
    //再次回到上一步 function reback(){ if(player_path_stack.length>0){
    var pre=player_path_stack.pop(); currentPos=pre; this._x =
    left+this.currentPos.col*_stepSize; this._y =
    top+this.currentPos.row*_stepSize; }
    if(boxes_path_stack.length>0 ){ var
    obj=boxes_path_stack.pop(); if(obj!=null){ var box=obj.box; var
    pos=obj.pos; box.pos=pos;
    box._x=box.left+box.pos.col*box._stepSize;
    box._y=box.top+box.pos.row*box._stepSize; } } } }

  6. class Box extends MovieClip { var pos:Pos; var left:Number; var
    top:Number; var _wall:MovieClip; var player:MovieClip; var
    _stepSize:Number; var _targets:Array; var
    finished:Boolean;//此箱子是还是不是达到指标地
    function Box() { left = 0; top = 0; finished = false; _stepSize =
    40; }
    //设置指标地 function setTargets(t) { _targets = new Array();
    _targets = t; }
    //设置箱子的原初地方之度外 function setStartPos(p) { pos = new
    Pos(p.col, p.row); this._x = pos.col*_stepSize+left; this._y =
    pos.row*_stepSize+top; }
    //移到下一个职位 function move() { var c =
    pos.getNextPos(player.dir); pos = c; this._x =
    left+pos.col*_stepSize; this._y = top+pos.row*_stepSize;
    gotTarget(); }
    //是还是不是达到目的地 function gotTarget() { for (var i = 0;
    i<_targets.length; i++) { if
    (this.pos.equals(_targets[i].pos)) { if
    (this.getDepth()>_targets[i].getDepth()) {
    this.swapDepths(_targets[i]); } this.finished = true; return; } }
    this.finished = false; }
    //获得一下个职位上物体的品类 function getNextObject():String { //var
    obj:String; var nextPos:Pos; nextPos = pos.getNextPos(player.dir);
    if (_wall.brickMatrix[nextPos.row][nextPos.col] == 1) { return
    “WALL”; } for (var i = 0; i<player.boxes.length; i++) { if
    (player.boxes[i].pos.equals(nextPos)) { return “BOX”; } } return
    “NOTHING”; } }

  7. class Matrix{ //用来存放在游戏各关中初阶分界面 static var
    matrixs:Array;
    function Matrix(){ matrixs=new Array(); //0:null //1:wall //2:player
    //3:box //4:target //5:target and box //1 2 3 4 5 6 7 8 9
    matrixs[0]= [[0, 0, 0, 0, 0, 0, 0, 0, 0],//1 [0, 0, 0, 0, 0,
    0, 0, 0, 0],//2 [0, 0, 0, 0, 0, 0, 0, 0, 0],//3 [0, 0, 0, 0, 0,
    0, 0, 0, 0],//4 [0, 0, 0, 0, 0, 0, 0, 0, 0],//5 [0, 0, 0, 0, 0,
    0, 0, 0, 0],//6 [0, 0, 0, 0, 0, 0, 0, 0, 0],//7 [0, 0, 0, 0, 0,
    0, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0, 0, 0, 0] //9 ];
    //1 2 3 4 5 6 7 8 9 matrixs[1]= [[0, 1, 1, 1, 1, 1, 1, 0,
    0],//1 [1, 1, 1, 0, 0, 0, 1, 0, 0],//2 [1, 0, 3, 0, 1, 0, 1, 1,
    0],//3 [1, 0, 1, 0, 0, 4, 0, 1, 0],//4 [1, 0, 0, 0, 0, 1, 0, 1,
    0],//5 [1, 1, 0, 1, 0, 0, 0, 1, 0],//6 [0, 1, 2, 0, 0, 1, 1, 1,
    0],//7 [0, 1, 1, 1, 1, 1, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0, 0, 0,
    0] //9 ]; //1 2 3 4 5 6 7 8 9 matrixs[2]= [[0, 0, 1, 1, 1, 1,
    1, 0, 0],//1 [1, 1, 1, 0, 0, 0, 1, 0, 0],//2 [1, 0, 3, 0, 1, 0,
    1, 1, 0],//3 [1, 0, 1, 0, 0, 4, 0, 1, 0],//4 [1, 0, 0, 0, 0, 1,
    0, 1, 0],//5 [1, 1, 3, 1, 4, 0, 0, 1, 0],//6 [0, 1, 2, 0, 0, 1,
    1, 1, 0],//7 [0, 1, 1, 1, 1, 1, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0,
    0, 0, 0] //9 ];

    //1 2 3 4 5 6 7 8 9 matrixs[3]= [[1, 1, 1, 1, 1, 1, 1, 1,
    0],//1 [1, 0, 0, 0, 1, 0, 0, 1, 0],//2 [1, 0, 0, 0, 0, 0, 0, 1,
    0],//3 [1, 1, 3, 1, 1, 0, 0, 1, 0],//4 [0, 1, 0, 4, 1, 0, 1, 1,
    1],//5 [0, 1, 0, 0, 0, 0, 2, 0, 1],//6 [0, 1, 0, 0, 1, 0, 0, 0,
    1],//7 [0, 1, 1, 1, 1, 1, 1, 1, 1],//8 [0, 0, 0, 0, 0, 0, 0, 0,
    0] //9 ];

    //1 2 3 4 5 6 7 8 9 matrixs[4]= [[1, 1, 1, 1, 1, 1, 1, 1,
    0],//1 [1, 0, 0, 0, 1, 0, 0, 1, 0],//2 [1, 0, 0, 0, 0, 0, 0, 1,
    0],//3 [1, 1, 5, 1, 1, 0, 0, 1, 0],//4 [0, 1, 0, 4, 1, 0, 1, 1,
    1],//5 [0, 1, 0, 5, 0, 3, 2, 0, 1],//6 [0, 1, 0, 0, 1, 0, 0, 0,
    1],//7 [0, 1, 1, 1, 1, 1, 1, 1, 1],//8 [0, 0, 0, 0, 0, 0, 0, 0,
    0] //9 ]; //1 2 3 4 5 6 7 8 9 matrixs[5]= [[0, 0, 1, 1, 1, 1,
    0, 0, 0],//1 [0, 1, 1, 0, 0, 1, 1, 1, 1],//2 [1, 1, 0, 0, 0, 0,
    0, 0, 1],//3 [1, 0, 3, 0, 1, 2, 1, 0, 1],//4 [1, 0, 1, 0, 4, 0,
    0, 0, 1],//5 [1, 0, 0, 3, 0, 1, 1, 1, 1],//6 [1, 1, 1, 0, 4, 1,
    0, 0, 0],//7 [0, 0, 1, 1, 1, 1, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0,
    0, 0, 0] //9 ]; //1 2 3 4 5 6 7 8 9 matrixs[6]= [[0, 0, 1, 1,
    1, 1, 0, 0, 0],//1 [0, 1, 1, 0, 0, 1, 1, 1, 1],//2 [1, 1, 0, 0,
    3, 0, 0, 0, 1],//3 [1, 0, 3, 0, 1, 2, 1, 0, 1],//4 [1, 0, 1, 0,
    4, 0, 0, 0, 1],//5 [1, 0, 4, 3, 0, 1, 1, 1, 1],//6 [1, 1, 1, 0,
    4, 1, 0, 0, 0],//7 [0, 0, 1, 1, 1, 1, 0, 0, 0],//8 [0, 0, 0, 0,
    0, 0, 0, 0, 0] //9 ]; //1 2 3 4 5 6 7 8 9 matrixs[7]= [[0, 1,
    1, 1, 1, 1, 0, 0, 0],//1 [0, 1, 0, 0, 0, 1, 0, 0, 0],//2 [1, 1,
    3, 1, 0, 1, 1, 1, 0],//3 [1, 0, 0, 0, 3, 2, 0, 1, 0],//4 [1, 0,
    1, 0, 0, 1, 0, 1, 0],//5 [1, 0, 1, 4, 0, 4, 0, 1, 0],//6 [1, 0,
    0, 0, 1, 1, 1, 1, 0],//7 [1, 1, 1, 1, 1, 0, 0, 0, 0],//8 [0, 0,
    0, 0, 0, 0, 0, 0, 0] //9 ]; //1 2 3 4 5 6 7 8 9 matrixs[8]=
    [[0, 1, 1, 1, 1, 1, 0, 0, 0],//1 [0, 1, 0, 0, 0, 1, 0, 0,
    0],//2 [1, 1, 3, 1, 0, 1, 1, 1, 0],//3 [1, 0, 0, 4, 3, 2, 0, 1,
    0],//4 [1, 0, 1, 0, 0, 1, 0, 1, 0],//5 [1, 0, 1, 4, 4, 3, 0, 1,
    0],//6 [1, 0, 0, 0, 1, 1, 1, 1, 0],//7 [1, 1, 1, 1, 1, 0, 0, 0,
    0],//8 [0, 0, 0, 0, 0, 0, 0, 0, 0] //9 ]; //1 2 3 4 5 6 7 8 9
    matrixs[9]= [[0, 1, 1, 1, 1, 1, 1, 1, 0],//1 [0, 1, 0, 2, 4,
    4, 4, 1, 0],//2 [0, 1, 0, 0, 0, 1, 1, 1, 1],//3 [1, 1, 1, 3, 0,
    0, 0, 0, 1],//4 [1, 0, 0, 0, 1, 3, 1, 0, 1],//5 [1, 0, 3, 0, 1,
    0, 0, 0, 1],//6 [1, 0, 0, 0, 1, 1, 1, 1, 1],//7 [1, 1, 1, 1, 1,
    0, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0, 0, 0, 0] //9 ]; //1 2 3 4 5 6
    7 8 9 matrixs[10]= [[0, 0, 1, 1, 1, 1, 0, 0, 0],//1 [0, 0, 1,
    0, 0, 1, 0, 0, 0],//2 [0, 0, 1, 0, 0, 1, 0, 0, 0],//3 [0, 0, 1,
    0, 0, 1, 1, 1, 0],//4 [0, 0, 1, 4, 3, 3, 2, 1, 0],//5 [0, 0, 1,
    0, 0, 4, 0, 1, 0],//6 [0, 0, 1, 0, 0, 1, 1, 1, 0],//7 [0, 0, 1,
    1, 1, 1, 0, 0, 0],//8 [0, 0, 0, 0, 0, 0, 0, 0, 0] //9 ]; }

    function getMatrix(d){ return matrixs[d]; }
    }

  8. //****************Manager.as*************
    //用来治本游戏 //全部的对象都入在那之中 //MovieClip类的子类 class
    Manager extends MovieClip { var wall:MovieClip; var
    player:MovieClip; var boxes:Array; var targets:Array; var
    stageNum:Number;//游戏的方今关数
    function Manager() { _x=50; _y=50; }
    //游戏开始化 function init(s) { stageNum = s;
    boxes = new Array(); targets = new Array();
    var brickMatrixT = new
    Matrix().getMatrix(stageNum);//依照关数从矩阵类中赢得相应的矩阵
    //修墙 wall = attachMovie(“Wall”, “wall”,
    this.getNextHighestDepth()); wall.setMatrix(brickMatrixT);
    wall.build();
    //创立三个游戏用户 player = attachMovie(“Player”, “plyaer”,
    this.getNextHighestDepth()); player.setWall(wall);
    player.setKeyHandle();//监听键盘输入
    for (var i = 0; i<brickMatrixT.length; i++) { for (var j = 0;
    j<brickMatrixT[0].length; j++) { if (brickMatrixT[i][j]
    == 2) { player.setStartPos(new Pos(j, i)); } if
    (brickMatrixT[i][j] == 3) { var d = this.getNextHighestDepth();
    var box = attachMovie(“Box”, “box”+i+j, d); box.setStartPos(new
    Pos(j, i)); box.player = player; box._wall = wall; boxes.push(box);
    } if (brickMatrixT[i][j] == 4) { var d =
    this.getNextHighestDepth(); var t = attachMovie(“Target”,
    “target”+i+j, d); t.setPos(new Pos(j, i)); targets.push(t); } if
    (brickMatrixT[i][j] == 5) { var d = this.getNextHighestDepth();
    var box = attachMovie(“Box”, “box”+i+j, d); box.setStartPos(new
    Pos(j, i)); box.player = player; box._wall = wall; box.finished =
    true; boxes.push(box); var d1 = this.getNextHighestDepth(); var t =
    attachMovie(“Target”, “target”+i+j, d1); t.setPos(new Pos(j, i));
    targets.push(t); } } }
    for (var i = 0; i<boxes.length; i++) {
    boxes[i].setTargets(targets); }
    player.setBoxes(boxes);
    player.swapDepths(this.getNextHighestDepth()); } //剖断游戏是或不是终止
    function ifWin() { var win = true; for (var i = 0;
    i<boxes.length; i++) { win = boxes[i].finished && win; }
    return win; } }

  9. 新建”Flash文档”,命名为”push_box”,并将它和上述脚本文件存在同样目录下.以下要做的正是创制要用到的电影剪辑,并将其和对应的台本文件建设构造链接.
  10. 按”Ctrl+F8″,新建贰个影片剪辑,命名称为”Player”,在编写制定状态下画贰个长,宽都为40象素的小丑(_stepSize=40),注意,小人的注册点放在左上脚.画完后在电影库中,右击”Player”,选拔”为动作脚下本导出”,别的不选.”标记符”,”As
    2.0类”都为影片剪辑名”Player”.要当心,大小写不能搞错,不然会出错.
  11. 按上述方法依次建构”Box”,”Target”剪辑.
  12. 按10创立名称叫”Brick”的剪辑,可是由于它不供给外界脚本文件,故”As
    2.0″中永不添.
  13. 按10确立”沃尔”剪辑,稍有分化的是,在编排状态下,第一帧中加”stop()”,第二帧中参预一个”Brick”剪辑.那样做是因为”Wall”在建筑时要求使用”Brick”.
  14. 按12建设构造”Manager”剪辑,分化的是索要点中“在第一帧导出”,而且第二帧加入的不是”Brick”,而是”Wall”,”Player”,”Box”,”Target”.
  15. 好了,一切就绪,大家能够测量试验一下了.在主时间轴上先是帧中中入语句:attachMovie(“Manager”,”game1″,_root.getNextHighestDepth());
    game1.init(1);就足以运作第一关了.
  16. 至于什么建立和煦的用户分界面,我们只需稍花点力气就化解了.

  示例:

 

点击这里下载源文件

  要是你还会有别的不知底之处,可发邮件或QQ给小编.xiake1860@ncepubj.edu.cn
QQ:407713**0 **