In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

tabuleiro mutilado tool

mitani's http://www.mundorpgmaker.com/forum/index.php?topic=74967.0
Get Adobe Flash player
by Thy 17 Jun 2011
    Embed
/**
 * Copyright Thy ( http://wonderfl.net/user/Thy )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4vUJ
 */

package {
    import flash.events.Event;
    import flash.display.GradientType;
    import flash.events.MouseEvent;
    import flash.display.Graphics;
    import flash.display.Sprite;
    public class FlashTest extends Sprite 
    {
        
        public var a:Array = [];
        
        public var bDown:Boolean;
        
        public var X:Number = 0, Y:Number = 0;
                   
        public var Xnew:Number = -1, Ynew:Number = -1;
                   
        public  var g:Graphics;
        
        public var o1:Sprite = new Sprite();
        public var o2:Sprite = new Sprite();
        
        
        public function FlashTest() 
        {
            g = this.graphics;
            
            {
                g.lineStyle(1);
                var i:int = -1;
                while(++i < 8)
                {
                    a[i] = new Array();
                    
                    var j:int = -1;
                    while(++j < 8)
                    {
                        g.beginFill((j + i) & 1 ? 0xFFFFFF : 0);
                        g.drawRect(j * 50, i * 50, 50, 50);
                        g.endFill();
                        
                        a[i][j] = true;
                    }
                    
                    
                    
                    
                }
                
                g.beginFill(0xFF0000);
                g.drawRect(0, 0, 50, 50);
                g.drawRect(7 * 50, 7 * 50, 50, 50);
                g.endFill();
                
                a[0][0] = false;
                a[7][7] = false;
            }
            
            o1.graphics.beginFill(0xFF);
            o1.graphics.drawRect(0, 0, 50, 50);
            o1.graphics.endFill();
            o2.graphics.beginFill(0xFFFF);
            o2.graphics.drawRect(0, 0, 50, 50);
            o2.graphics.endFill();
            
            o1.x = o2.x = o1.y = o2.y = -50;
            
            this.addChild(o1);
            this.addChild(o2);
            
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, fDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, fUp);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, fMove);
            
            stage.addEventListener(Event.ENTER_FRAME, ef);
        }
        
        private function fMove(e:MouseEvent):void 
        {
            if (!bDown)
                return;
                
            Xnew = (mouseX / 50) >> 0;
            Ynew = (mouseY / 50) >> 0;
            
            if (!a[Ynew][Xnew] || !((Xnew - X) * (Xnew - X) + (Ynew - Y) * (Ynew - Y) == 1))
            {
                Xnew = -1;
                Ynew = -1;
                o2.x = o2.y = -50
                return;
            }
            
            o2.x = Xnew * 50;
            o2.y = Ynew * 50;
            
        }
        
        private function fUp(e:MouseEvent):void 
        {
            
            if (!bDown)
                return;
            
            bDown = false;
            
            if (Xnew < 0 || Ynew < 0 || !(a[Y][X] && a[Ynew][Xnew]))
            {
                Xnew = -1; Ynew = -1;
                X = -1; Y = -1;
                o1.x = o1.y = o2.x = o2.y = -50
                
                return;
            }
            
            marcar(X,Y,Xnew,Ynew);
            o1.x = o1.y = o2.x = o2.y = -50;
        }
        
        private function marcar(x1:int, y1:int, x2:int, y2:int):void
        {
            g.beginFill(0xFF);
            g.drawRect(x1 * 50 + 2, y1 * 50 + 2, 46, 46);
            g.endFill();
            
            g.beginFill(0xFFFF);
            g.drawRect(x2 * 50 + 2, y2 * 50 + 2, 46, 46);
            g.endFill();
            
            a[y1][x1] = false;
            a[y2][x2] = false;
            
            if(wait < 0)
                wait = 10;
            
        }

        
        private function fDown(e:MouseEvent):void
        {
            
            X = (mouseX / 50) >> 0;
            Y = (mouseY / 50) >> 0;
            
            if ( !a[Y][X] )
            {
                X = -1;
                Y = -1;
                return;
            }
            
            bDown = true;
            
            o1.x = X * 50;
            o1.y = Y * 50;
            
            o2.x = o2.y = -50
        }
    
    
        private var wait:int = 60;
        private function ef (e:Event):void
        {
            if(--wait)
                return;
                
            trace("_____");
            
            // varrer
            {
                var pos:int = 0;
                var i:int = -1;
                var j:int;
                
                var x1:int, x2:int, y1:int, y2:int;
                
                while(++i < 8)
                {
                    y1 = i;
                    j = -1;
                    while(++j < 8)
                    {
                        x1 = j;
                        
                        if (!a[y1][x1])
                            continue;
                        
                        pos = 0;
                        
                        if(x1 > 0 && a[y1][x1-1] ) 
                        {
                            x2 = x1-1;
                            y2 = y1;
                            ++pos;
                        }

                        if(x1 < 7 && a[y1][x1+1] ) 
                        {
                            x2 = x1+1;
                            y2 = y1;
                            ++pos;
                        }
                        
                        if( y1 > 0 && a[y1-1][x1] ) 
                        {
                            x2 = x1;
                            y2 = y1-1;
                            ++pos;
                        }
                        
                        if( y1 < 7 && a[y1+1][x1] ) 
                        {
                            x2 = x1;
                            y2 = y1+1;
                            ++pos;
                        }
                        
                        if (pos == 1)
                        {
                            marcar(x1, y1, x2, y2);
                            wait = 10;
                            return;
                        }

                       
                    }
                }

            }
        }
    
    }
    
    
    
    
    

}