flash连连看游戏设计视频教程

编程技术  /  houtizong 发布于 3年前   120

全屏观看地址:
[url=http://vhead.blog.sina.com.cn/player/outer_player.swf?auto=0&vid=14561576&uid=1053530897&pid=346&tid=1]
视频1地址
[/url]
[url=http://vhead.blog.sina.com.cn/player/outer_player.swf?auto=0&vid=14562838&uid=1053530897&pid=346&tid=1]
视频2地址
[/url]
[url=http://vhead.blog.sina.com.cn/player/outer_player.swf?auto=0&vid=14562439&uid=1053530897&pid=346&tid=1]
视频3地址
[/url]
 
源文件及 PPT 下载:
[url=http://www.fs2you.com/files/76b3bea8-41d3-11dd-ba6f-001143e7b41c/]
http://www.fs2you.com/files/76b3bea8-41d3-11dd-ba6f-001143e7b41c/
[/url]
 
[1b]代码公布(数字版):[/1b]
[1b]Card.as:[/1b]
package {
 import flash.display.Sprite;
 import flash.text.TextField;
 import flash.text.TextFormat;
 import flash.filters.*;
 import flash.events.MouseEvent;
 public class Card extends Sprite {
  public var id:int;
  public var W:Number = 30;
  public var H:Number = 40;
  public var i:int;
  public var j:int;
  public var TargetCard:Card;
  private var color:uint = 0xcccccc;
  public var Path:Array = new Array();
  private var pressed:Boolean = false;
  
  public var line:Sprite = new Sprite();
  public function Card(id:int) {
   this.id = id;
   init();
  }
  function init():void {
   graphics.beginFill(color);
   graphics.drawRect(0,0,W,H);
   graphics.endFill();
   var Text:TextField = new TextField();
   Text.text = String(id);
   Text.selectable = false;
   Text.autoSize = "left";
   var tf:TextFormat = new TextFormat(null,25);
   // tf.size = 25;
   Text.setTextFormat(tf);
   addChild(Text);
   
   addEventListener(MouseEvent.MOUSE_OVER, MouseOver);
   addEventListener(MouseEvent.MOUSE_OUT, MouseOut);
  }
  function setIndex(a:int, b:int):void {
   i = a;
   j = b;
  }
  function Pressed():void {
   pressed = true;
  }
  function UnPressed():void {
   pressed = false;
   this.filters = null;
  }
  function MouseOver(evt:MouseEvent):void {
   var blur:BevelFilter = new BevelFilter();
   var shadow:DropShadowFilter = new DropShadowFilter(10);
   var f:Array = new Array();
   f.push(blur);
   f.push(shadow);
   this.filters = f;
  }
  function MouseOut(evt:MouseEvent):void {
   if (pressed == false) {
    this.filters = null;
   }
  }
 }
}
============================================
[1b]Main.as[/1b]
package {
 import flash.display.Sprite;
 import flash.events.MouseEvent;
 import flash.events.Event;
 public class Main extends Sprite {
  var Row:uint = 4;
  var Colum:uint = 5;
  var MarginLeft:Number = 180;
  var MarginTop:Number = 100;
  var oldCard:Card;
  var map:Array;
  public function Main() {
   init();
  }
  
  function init():void {
   map = new Array(Row + 2);
   var numArray:Array = new Array();
   for (var i:uint = 0; i    numArray[i] = new Array();
    var num:uint = 0;
    for (var j:uint = 0; j     numArray[i][j] = ++num;
    }
   }
   for (i = 0; i    for (j = 0; j     var Rani:uint = Math.floor(Math.random() * Row);
     var Ranj:uint = Math.floor(Math.random() * Colum);
     var temp:uint = numArray[i][j];
     numArray[i][j] = numArray[Rani][Ranj];
     numArray[Rani][Ranj] = temp;
    }
   }
   for (i = 0; i    map[i] = new Array(Colum + 2);
    for (j = 0; j     if (i ==0 || j ==0 || i == Row + 1 || j == Colum + 1) {
      map[i][j] = 0;
     } else {
      map[i][j] = 1;
     }
    }
   }
   
   for (i = 0; i    for (j = 0; j     var card:Card = new Card(numArray[i][j]);
     addChild(card);
     card.x = MarginLeft + j * (card.W + 2);
     card.y = MarginTop + i * (card.H + 2);
     card.setIndex(i + 1, j + 1);
     card.addEventListener(MouseEvent.CLICK, onClick);
    }
   }
  }
  function onClick(evt:MouseEvent):void {
   try {
    var currentCard:Card = Card(evt.target.parent);
   } catch (error:Error) {
    currentCard = Card(evt.target);
   }
   if (oldCard == null) {
    oldCard = currentCard;
    oldCard.Pressed();
   } else {
    oldCard.TargetCard = currentCard;
    // successfully matched!
    if (isMatched()) {
     addChild(oldCard.line)
     oldCard.line.graphics.clear();
     oldCard.line.graphics.lineStyle(2);
     
     var node:Object = oldCard.Path.shift();
     oldCard.line.graphics.moveTo(MarginLeft + node.y * oldCard.W - oldCard.W / 2, MarginTop + node.x * oldCard.H - oldCard.H / 2);
     
     oldCard.addEventListener(Event.ENTER_FRAME, ToLink);
     oldCard = null;
    } else {
     // Can not Match!
     oldCard.UnPressed();
     oldCard = null;
    }
   }
  }
  function ToLink(evt:Event):void {
   var card:Card = Card(evt.target);
   if (card.Path.length > 0) {
    var node:Object = card.Path.shift();
    card.line.graphics.lineTo(MarginLeft + node.y * card.W - card.W / 2, MarginTop + node.x * card.H - card.H / 2);
   } else {
    
    map[card.i][card.j] = 0;
    map[card.TargetCard.i][card.TargetCard.j] = 0;
    card.removeEventListener(Event.ENTER_FRAME, ToLink);
    removeChild(card);
    removeChild(card.line);
    removeChild(card.TargetCard);
   }
  }
  
  function isMatched():Boolean {
   if (oldCard == oldCard.TargetCard || oldCard.id != oldCard.TargetCard.id) {
    return false;
   }
   
   var x1:uint = oldCard.i;
   var y1:uint = oldCard.j;
   var x2:uint = oldCard.TargetCard.i;
   var y2:uint = oldCard.TargetCard.j;
   
   var node:Object = new Object();
   var tempPath:Array = new Array();
   
   for (var i:uint = 0; i    var count:uint = 0;
    tempPath.splice(0);
    
    var step:int = (y1 > i) ? -1 : 1;
    for (var j = y1; j != i; j += step) {
     count += map[x1][j];
     node = {x:x1,y:j};
     tempPath.push(node);
    }
    step = (x1 > x2) ? -1 : 1;
    for (j = x1; j != x2; j += step) {
     count += map[j][i];
     node = {x:j,y:i};
     tempPath.push(node);
    }
    step = (i    for (j = i; j != y2; j+= step) {
     count += map[x2][j];
     node = {x:x2,y:j};
     tempPath.push(node);
    }
    if (count == 1) {
     if (oldCard.Path.length == 0 || tempPath.length      oldCard.Path = tempPath.slice();
     }
    }
   }
   for (i = 0; i    count = 0;
    tempPath.splice(0);
    step = (i    for (j = x1; j != i; j += step) {
     count += map[j][y1];
     node = {x:j,y:y1};
     tempPath.push(node);
    }
    step = (y2 > y1) ? 1 : -1;
    for (j = y1; j != y2; j += step) {
     count += map[i][j];
     node = {x:i,y:j};
     tempPath.push(node);
    }
    step = (x2 > i) ? 1 : -1;
    for (j = i; j != x2; j += step) {
     count += map[j][y2];
     node = {x:j,y:y2};
     tempPath.push(node);
    }
    if (count == 1) {
     if (oldCard.Path.length == 0 || tempPath.length      oldCard.Path = tempPath.slice();
     }
    }
   }
   
   if (oldCard.Path.length > 0) {
    node = {x:x1, y:y1};
    oldCard.Path.unshift(node);
    node = {x:x2, y:y2};
    oldCard.Path.push(node);
    return true;
   }
   return false;
  }
 }
}
 
详细地址
http://blog.sina.com.cn/s/blog_3ecb9b110100a1wk.html
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/4875.html

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客