The code is not integrated or optimized. Algorithms are important;
Package move {import flash. display. bitmapData; import flash. display. sprite; public class Tile extends Sprite {/*** unit entity class ** // *** bitmap data **/private var _ bit: BitmapData; /***** name **/private var _ m_type: String = ""; public function Tile (_ bit: BitmapData) {_ bit = _ bit; this. graphics. beginBitmapFill (_ bit); this. graphics. drawRect (0, 0, 32); this. graphics. endFill ();} public function get m_type (): String {return _ m_type;} public function set m_type (value: String): void {_ m_type = value ;} public function get bit (): BitmapData {return _ bit;} public function set bit (value: BitmapData): void {_ bit = value ;}}}
Package move {import com. greensock. tweenMax; import com. greensock. easing. back; import com. greensock. easing. bounce; import flash. display. sprite; import flash. events. event; import mx. controls. alert; import mx. core. UIComponent; public class View extends UIComponent {public var MoveBol: Boolean = false; private var maskSprite: Sprite; public var sourceArr: Array = []; private var line: Sprite; private var TypeArr: Array = []; private var solt_index: int = 0; public function View () {SetView (); this. addEventListener (SoltsEvent. STOP_MOVE, ViewStopMoveHandler);}/*** initialize and set the position **/private function SetView (): void {for (var I: int = 0; I <5; I ++) {var vs: ViewSource = new ViewSource ();. x = 200 + I * 50;. y = 300;. index = I;. interSpeed = 0.1 + Math. random () * 0.4; sourceArr. push (vs); this. addChild (vs);} CreatMask (); SetLine ();} public function setMoveType (): void {if (MoveBol) {setType (1); TypeArr = [];} else {setType (2) ;}}/*** set acceleration or deceleration in different States **/private function setType (ii: uint = 0): void {for (var I: uint = 0; I <sourceArr. length; I ++) {var vs: ViewSource = sourceArr [I] as ViewSource;. type = ii;. start () ;}/ ***** set mask **/private function CreatMask (): void {maskSprite = new Sprite (); maskSprite. graphics. beginFill (0x000000); maskSprite. graphics. drawRect (100,300,400,332); maskSprite. graphics. endFill (); this. mask = maskSprite;}/*** draw two lines **/private function SetLine (): void {line = new Sprite (); line. graphics. lineStyle (2); line. graphics. beginFill (0, 0); line. graphics. drawRect (100,445,400, 40); line. graphics. endFill (); this. addChild (line);} private function ViewStopMoveHandler (event: SoltsEvent): void {var arr: Array = event.info as Array; var type: String = arr [0] ;}}
Package move {import com. greensock. tweenMax; import flash. display. sprite; import flash. events. event; import flash. events. mouseEvent;/*** Array object class in the column **/public class ViewSource extends Sprite {public var BitSourceArr: Array = []; public var speed: Number = 6; public var interSpeed: Number = 0.3;/*** switch? Control acceleration or deceleration **/public var type: uint = 0;/*** maximum and minimum heights **/private var maxHeight: Number; private var minHeight: Number; /*** in the column number? **/Public var index: int = 0; public function ViewSource () {setViewTile ();}/*** set type status **/public function setViewTile (): void {for (var I: int = 0; I <8; I ++) {var how: int = Math. floor (I/4); var sow: int = I % 4; var tile: Tile = new Tile (GetBitmapDataClass. getBitmapData (sow * 3, how * 4); switch (I) {case 0: tile. m_type = "boat"; break; case 1: tile. m_type = "Sailing"; break; case 2: tile. m_type = "balloon"; break; case 3: tile. m_type = ""; break; case 4: tile. m_type = "Che ma"; break; case 5: tile. m_type = "tent"; break; case 6: tile. m_type = "empty car"; break; case 7: tile. m_type = "full car"; break;} BitSourceArr. push (tile);} BitSourceArr = this. setBitArray (BitSourceArr); setLocation (); this. addEventListener (MouseEvent. MOUSE_DOWN, MouseDownHandler);}/*** disrupt Array sorting **/private function setBitArray (_ ba: Array): Array {var length: uint = _ ba. length; var temp1: Array = []; for (var I: int = 0; I <length; I ++) {temp1.push (I);} var temp2: array = []; for (var ii: int = 0; ii <length; ii ++) {temp2 [ii] = temp1.splice (Math. random () * temp1.length, 1);} var temp3: Array = []; for (var iii: int = 0; iii <length; iii ++) {temp3 [iii] = _ ba [temp2 [iii];} return temp3;}/*** set each position of a column **/private function setLocation (): void {for (var I: int = 0; I <BitSourceArr. length; I ++) {var tile: Tile = BitSourceArr [I] as Tile; tile. y = I * 50; this. addChild (tile);} maxHeight = 300; minHeight = 0;}/*** start acceleration **/public function StartMove (): void {speed + = interSpeed; if (speed> = 20) {speed = 20 ;}/ *** start to slow down **/public function StopMove (): void {if (speed> 1) {speed-= interSpeed;} else {/*** algorithm **/if (BitSourceArr [1]. y> 0) {speed = 1;} else {speed = 0; this. removeEventListener (Event. ENTER_FRAME, OnEnterFrameHandler); this. parent. dispatchEvent (new SoltsEvent ([Tile (BitSourceArr [4]). m_type, this. index], SoltsEvent. STOP_MOVE); trace ("Send:" + Tile (BitSourceArr [4]). m_type) ;}} public function Start (): void {this. addEventListener (Event. ENTER_FRAME, OnEnterFrameHandler);} private function OnEnterFrameHandler (event: Event): void {for (var I: int = 0; I <BitSourceArr. length; I ++) {var tile: Tile = BitSourceArr [I] as Tile; tile. y-= speed;} if (type = 1) {this. startMove ();} else if (type = 2) {StopMove ();} if (Tile (BitSourceArr [0]). y <=-50) {var firstOne: Tile = BitSourceArr. shift (); var lastOne: Tile = BitSourceArr [BitSourceArr. length-1]; firstOne. y = lastOne. y + 50; BitSourceArr. push (firstOne) ;}} private function MouseDownHandler (event: MouseEvent): voidjavasif(event.tar get is tile+trace(bitsourcearr.indexof(event.tar get) + "---" inclutile(event.tar get ). m_type );}}}}
package move{import flash.events.Event;public class SoltsEvent extends Event{public var info:*;public static const STOP_MOVE:String="stop_move";public function SoltsEvent(_info:*,eventname:String){super(eventname);this.info=_info;}}}
<? Xml version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: fx = "http://ns.adobe.com/mxml/2009" xmlns: s = "library: // ns.adobe.com/flex/spark" xmlns: mx = "library: // ns.adobe.com/flex/mx "minWidth =" 955 "minHeight =" 600 "creationComplete =" init () "> <s: layout> <s: BasicLayout/> </s: layout> <fx: Declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </fx: Declarations> <fx: Script> <! [CDATA [import move. getBitmapDataClass; import move. tile; import move. view; import move. viewSource; import mx. core. UIComponent; private var view: View; private function init (): void {view = new View (); addElement (view);} private function MoveHandler (): void {view. moveBol =! View. moveBol; view. setMoveType () ;}]]> </fx: Script> <s: Button x = "596" y = "170" label = "Button" click = "MoveHandler () "/> </s: Application>
Graphics: