AS3 发表于 2013-1-25 03:33:42

2个连连看

http://bbs.9ria.com/viewthread.php?tid=84342&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000


package {      import flash.display.Sprite;                /**         * ...         * @author zlt         */      public class Mains extends Sprite      {                private var arrM:Array;                private var Frist:Pic;                private var Second:Pic;                private var spr:Sprite                private var isOk:Boolean;                public function Mains()                {                        arrM = new Array();                        spr = new Sprite();                                                this.addEventListener(ClickEvent.ENTER, getLine);                        init();                }                private function init():void                {                        for (var i:int = 0; i < 10; i++ )                        {                              var arrs:Array = new Array();                              for (var s:int = 0; s < 20; s++ )                              {                                        var pic:Pic = new Pic(this);                                        pic.x = s * 20;                                        pic.y = i * 20;                                        pic.Xs = i;                                        pic.Ys = s;                                        pic.number = Math.round(Math.random() * 100 / 20).toString();                                        pic.txt.text = pic.number;                                        this.addChild(pic);                                        arrs.push(pic);                              }                              arrM.push(arrs);                                                      }                        this.addChild(spr);                }                private function getLine(e:ClickEvent):void                {                        if (Frist == null)                        {                              Frist = e._obj as Pic;                              return;                        }                        else if (Second == null )                        {                              Second = e._obj as Pic;                              isOk = false;                              if (Frist.number == Second.number && Frist.number != "" && Second.number != "")                              {                              drawLine(Frist, Second);                              }                              else                              {                                        isOk = false;                              }                              if (isOk)                              {                                        isOk = false;                                        spr.graphics.clear();                                        spr.graphics.lineStyle(1, 0XFF0000);                                        spr.graphics.moveTo(Frist.x + 10, Frist.y + 10);                                        spr.graphics.lineTo(arrM.x+10,arrM.y+10);                                        spr.graphics.lineTo(arrM.x+10,arrM.y+10);                                        spr.graphics.lineTo(Second.x + 10, Second.y + 10);                                        spr.graphics.endFill();                                        trace("1:", Frist.Xs, Frist.Ys, "2:", tempX1, tempY1, "3:", tempX2, tempY2, "4:", Second.Xs, Second.Ys);                              }                              Frist = Second = null;                        }                        Frist = Second = null;                                        }                private var tempX1:int;                private var tempX2:int;                private var tempY1:int;                private var tempY2:int;                private function drawLine(a:Pic, b:Pic):void                {                        if (a == null || b == null)                        {                              Frist = null;                              Second = null;                              return;                        }                        //涓よ€呭湪涓€鏉℃í杞翠笂鐨勬儏鍐?                                                if (a.Xs == b.Xs && a.Ys != b.Ys)                        {                              var onVol:Boolean = true;                              if (Math.abs(a.Ys - b.Ys) == 1)                              {                                        a.number = a.txt.text = "";                                        b.number = b.txt.text = "";                                        tempX1 = a.Xs;                                        tempY1 = a.Ys;                                        tempX2 = b.Xs;                                        tempY2 = b.Ys;                                        isOk = true;                                        return;                              }                              else                              {                                        //鍒ゆ柇鍚屼竴鏉$嚎鐨勮矾寰?                                        for (var i:int = Math.min(a.Ys, b.Ys) + 1; i < Math.max(a.Ys, b.Ys); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      onVol = false;                                                }                                        }                                        //鍒ゆ柇涓や釜鎶樼偣                                        if (!onVol)                                        {                                                trace(a.Xs, a.Ys, b.Xs, b.Ys);                                                var temp1:Boolean=true;                                                var temp2:Boolean=true;                                                var temp3:Boolean=true;                                                for (i = 0; i < arrM.length; i++ )                                                {                                                      trace(arrM.number,arrM.number)                                                      if (arrM.number == ""&&arrM.number =="")                                                      {                                                                trace("空余的点",i,a.Ys,i,b.Ys);                                                                for (var s:int = Math.min(a.Xs, i) + 1; s < Math.max(a.Xs, i); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp1 = false;                                                                        }                                                                }                                                                for (s = Math.min(a.Xs, i) + 1; s < Math.max(a.Xs, i); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp2 = false;                                                                        }                                                                }                                                                for (s = Math.min(a.Ys, b.Ys) + 1; s < Math.max(a.Ys, b.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp3 = false;                                                                        }                                                                }                                                      }                                                      else                                                      {                                                                continue;                                                      }                                                      if (temp1 && temp2 && temp3)                                                      {                                                                tempX1 = i;                                                                tempY1 = a.Ys;                                                                tempX2 = i;                                                                tempY2 = b.Ys;                                                                a.number = a.txt.text = "";                                                                b.number = b.txt.text = "";                                                                isOk = true;                                                                return;                                                                                                                        }                                                      else                                                      {                                                                temp1 = temp2 = temp3 = true;                                                                continue;                                                      }                                                }                                        }                                        else                                        {                                                tempX1 = a.Xs;                                                tempY1 = a.Ys;                                                tempX2 = b.Xs;                                                tempY2 = b.Ys;                                                a.number = a.txt.text = "";                                                b.number = b.txt.text = "";                                                isOk = true;                                                return;                                        }                              }                        }                        //涓よ€呭湪涓€鏉$珫杞翠笂鐨勬儏鍐?                                                if (a.Xs != b.Xs && a.Ys == b.Ys)                        {                              onVol = true;                              if (Math.abs(a.Xs- b.Xs) == 1)                              {                                        a.number = a.txt.text = "";                                        b.number = b.txt.text = "";                                        tempX1 = a.Xs;                                        tempY1 = a.Ys;                                        tempX2 = b.Xs;                                        tempY2 = b.Ys;                                        isOk = true;                                        return;                              }                              else                              {                                        //鍒ゆ柇鍚屼竴鏉$嚎鐨勮矾寰?                                        for (i = Math.min(a.Xs, b.Xs) + 1; i < Math.max(a.Xs, b.Xs); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      onVol = false;                                                }                                        }                                        //鍒ゆ柇涓や釜鎶樼偣                                        if (!onVol)                                        {                                                temp1=true;                                                temp2=true;                                                temp3=true;                                                for (i = 0; i < arrM.length; i++ )                                                {                                                      if (arrM.number=="" && arrM.number == "")                                                      {                                                                for (s = Math.min(i, a.Ys) + 1; s < Math.max(i, a.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp1 = false;                                                                        }                                                                }                                                                for (s = Math.min(i, a.Ys) + 1; s < Math.max(i, a.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp2 = false;                                                                        }                                                                }                                                                for (s = Math.min(a.Xs, b.Xs) + 1; s < Math.max(a.Xs, b.Xs); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp3 = false;                                                                        }                                                                }                                                      }                                                      else                                                      {                                                                continue;                                                      }                                                      if (temp1 && temp2 && temp3)                                                      {                                                                tempX1 = a.Xs;                                                                tempY1 = i;                                                                tempX2 = b.Xs;                                                                tempY2 = i;                                                                a.number = a.txt.text = "";                                                                b.number = b.txt.text = "";                                                                isOk = true;                                                                return;                                                                                                                        }                                                      else                                                      {                                                                temp1 = temp2 = temp3 = true;                                                                continue;                                                      }                                                }                                        }                                        else                                        {                                                tempX1 = a.Xs;                                                tempY1 = a.Ys;                                                tempX2 = b.Xs;                                                tempY2 = b.Ys;                                                a.number = a.txt.text = "";                                                b.number = b.txt.text = "";                                                isOk = true;                                                return;                                        }                              }                        }                        //涓よ€呴兘涓嶇浉浜ょ殑鎯呭喌                                                if (a.Xs != b.Xs && a.Ys != b.Ys)                        {                              var tempPoint1:Boolean = true;                              var tempPoint2:Boolean = true;                              if (arrM.number == "")                              {                                        trace("first")                                        for (i = Math.min(a.Xs, b.Xs) + 1; i < Math.max(a.Xs, b.Xs); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      tempPoint1 = false;                                                }                                        }                                        for (i = Math.min(a.Ys, b.Ys) + 1; i < Math.max(a.Ys, b.Ys); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      tempPoint1 = false;                                                }                                        }                              }                              else                              {                                        tempPoint1 = false;                              }                              if (tempPoint1)                              {                                        trace("first success")                                        tempX1 = a.Xs;                                        tempY1 = b.Ys;                                        tempX2 = a.Xs;                                        tempY2 = b.Ys;                                        a.number = a.txt.text = "";                                        b.number = b.txt.text = "";                                        isOk = true;                                        return;                              }                              else                              {                                        if (arrM.number == "")                                        {                                        trace("second")                                        for (i = Math.min(a.Xs, b.Xs) + 1; i < Math.max(a.Xs, b.Xs); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      tempPoint2 = false;                                                }                                        }                                        for (i = Math.min(a.Ys, b.Ys) + 1; i < Math.max(a.Ys, b.Ys); i++ )                                        {                                                if (arrM.number != "")                                                {                                                      tempPoint2 = false;                                                }                                        }                                        }                                        else                                        {                                                tempPoint2 = false;                                        }                              }                              if (tempPoint2)                              {                                        trace("second success")                                        tempX1 = b.Xs;                                        tempY1 = a.Ys;                                        tempX2 = b.Xs;                                        tempY2 = a.Ys;                                        a.number = a.txt.text = "";                                        b.number = b.txt.text = "";                                        isOk = true;                                        return;                              }                              //横向平行线                                                temp1=true;                                                temp2=true;                                                temp3=true;                                                for (i = 0; i < arrM.length; i++ )                                                {                                                      if (arrM.number=="" && arrM.number == "")                                                      {                                                                for (s = Math.min(i, a.Ys) + 1; s < Math.max(i, a.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp1 = false;                                                                        }                                                                }                                                                for (s = Math.min(i, b.Ys) + 1; s < Math.max(i, b.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp2 = false;                                                                        }                                                                }                                                                for (s = Math.min(a.Xs, b.Xs) + 1; s < Math.max(a.Xs, b.Xs); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp3 = false;                                                                        }                                                                }                                                      }                                                      else                                                      {                                                                continue;                                                      }                                                      if (temp1 && temp2 && temp3)                                                      {                                                                tempX1 = a.Xs;                                                                tempY1 = i;                                                                tempX2 = b.Xs;                                                                tempY2 = i;                                                                a.number = a.txt.text = "";                                                                b.number = b.txt.text = "";                                                                isOk = true;                                                                return;                                                                                                                        }                                                      else                                                      {                                                                temp1 = temp2 = temp3 = true;                                                                continue;                                                      }                                                }                              //纵向平行线                                                temp1=true;                                                temp2=true;                                                temp3=true;                                                for (i = 0; i < arrM.length; i++ )                                                {                                                      trace(arrM.number,arrM.number)                                                      if (arrM.number == ""&&arrM.number =="")                                                      {                                                                trace("空余的点",i,a.Ys,i,b.Ys);                                                                for (s = Math.min(a.Xs, i) + 1; s < Math.max(a.Xs, i); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp1 = false;                                                                        }                                                                }                                                                for (s = Math.min(b.Xs, i) + 1; s < Math.max(b.Xs, i); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp2 = false;                                                                        }                                                                }                                                                for (s = Math.min(a.Ys, b.Ys) + 1; s < Math.max(a.Ys, b.Ys); s++ )                                                                {                                                                        if (arrM.number != "")                                                                        {                                                                              temp3 = false;                                                                        }                                                                }                                                      }                                                      else                                                      {                                                                continue;                                                      }                                                      if (temp1 && temp2 && temp3)                                                      {                                                                tempX1 = i;                                                                tempY1 = a.Ys;                                                                tempX2 = i;                                                                tempY2 = b.Ys;                                                                a.number = a.txt.text = "";                                                                b.number = b.txt.text = "";                                                                isOk = true;                                                                return;                                                                                                                        }                                                      else                                                      {                                                                temp1 = temp2 = temp3 = true;                                                                continue;                                                      }                                                }                                                                                                                                        }                }      }      }
页: [1]
查看完整版本: 2个连连看