| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 503 人关注过本帖
标题:打下们帮我找一下这个程序的错误
只看楼主 加入收藏
yukun314
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:35
专家分:120
注 册:2010-4-18
结帖率:100%
收藏
 问题点数:0 回复次数:1 
打下们帮我找一下这个程序的错误
package kyodai.map;
import java.awt.*;
import javax.swing.*;
import kyodai.*;
/* *消除连连看方块的类*/
public class AnimateDelete implements Runnable
{
    static JButton[]dots;
    static long delay=201;
    int []array=new int[44];//最大距离只可能为2行1列
    private int count=0;
    private volatile Thread thread;
    public AnimateDelete(JButton[]dots)
    {
       this.dots=dots;
       array=new int[0];
     }
       /**初始化*/
    public AnimateDelete(int direct,point a,point b)
    {
        initArray();
        calcTwoPoint(direct,a,b);
        start();
    }
     /**direct方向:1表示a,b在同一条直线上,b,c在同一竖线上:0表示a,b在同一竖线上,b,c在同一直线上*/
    public AnimateDelete(int direct,point a,point b,point c)
    {
         initArray();
         if(direct==1)      //先横后竖
           {
               calcTwoPoint(1,a,b);
               count--;
               calcTwoPoint(0,a,b);
           }
         else
           {
               calcTwoPoint(0,a,b);
               count--;
               calcTwoPoint(1,a,b);
           }
         start();
    }
    /**direct方向,1表示a,b在同横线上,b,c在同一竖线上,c,d为横线:0表示a,b在同一竖线上,b,c在同一直线上,c,d为竖线*/
    public AnimateDelete(int direct,point a,point b,point c,point d)
    {
         initArray();
         if(direct==1)      //横,竖,横方式处理         
         {
               calcTwoPoint(1,a,b);
               count--;
               calcTwoPoint(0,b,c);
               count--;
               calcTwoPoint(1,c,d);
           }
         else          //竖横竖方式处理
           {
               calcTwoPoint(0,a,b);
               count--;
               calcTwoPoint(1,b,c);
               count--;
               calcTwoPoint(0,c,d);
           }
         start();
    }
    /**计算消除的两点*/
    private void calcTwoPoint(int direct,point a,point b)
    {
        int offset=0;
        if(direct==1)      //横向连接
          {
              if(a.y>b.y)       //a点向b点是从右向左在水平线上消除
                 {
                     for(int y=a.y;y>=b.y;y--)
                         {
                             offset=a.x*Setting.COLUMN+y;
                             array[count]=offset;
                             count++;
                         }
                 }
               else             //a点向b点是从左向右在水平线上消除
                   {
                     for(int y=a.y;y<=b.y;y++)
                         {
                             offset=a.x*Setting.COLUMN+y;
                             array[count]=offset;
                             count++;
                         }
                 }
          }
       else
          {
             if(a.x>b.x)         //a点向b点是从下向上垂直消除
                 {
                    for(int x=a.x;x>=b.x;x--)
                       {
                          offset=x*Seting.COLUMN+a.y;
                          array[count]=offset;
                          count+;
                       }
                 }
              else           //a点向b点是从上向下垂直消除
                 {
                    for(int x=a.x;x<=b.x;x++)
                       {
                          offset=x*Seting.COLUMN+a.y;
                          array[count]=offset;
                          count+;
                       }
                 }
          }
     }
          /***设置动画速度*/
     public void SetSpeed(int speed)
     {
         delay=speed*10;
     }
     private void initArray()
    {
         if(array==null||array.length==0)
            {
                return;
            }       www.
     }
     public void test()
     {
         if(array==null||array.length==0)
            {
                return;
            }
          for(int i=0;i<array.length;i++)
             {
                 if(array[i]!=-1)
                    {
                       message("["+array[i]+"]");
                    }
             }
          System.out.println();
      }
      public void start()
      {
          thread=new Thread(this);
          thread.start();
      }
      public void run()
      {
          if(count<2)
            {
                return;
            }
          Thread currentThread=Thread currentThread();
          boolean animate=true;
          while(thread==currentThread&&animate)
            {
               for(int i=1;i<count-1;i++)
                  {
                      dots[array[i]].setEnabled(true);
                      dots[array[i]].setIcon(kyodai.Guidelcon);
                      try
                      {
                          thread.sleep(delay);
                      }
                     catch(InterruptedException ex)
                         {}
                  }
                for(int i=1;i<count-1;i++)
                  {
                      dots[array[i]].setIcon(null);
                      dots[array[i]].setEnabled(false);
                      try
                      {
                          thread.sleep(delay);
                      }
                     catch(InterruptedException ex)
                         {}
                   }
              dots[array[0]].setIcon(null);
              dots[array[0]].setEnabled(false);
              dots[array[array-1]].setIcon(null);
              dots[array[array-1]].setEnabled(false);
              animate=false;
           }
        stop();
      }
    public void stop()
      {
         if(thread!=null)
            {
                thread=null;
            }
      }
   void message(String str)
      {
           System.out.println(str);
      }      
}  151
package kyodai.map;
import java.awt.Poimt;/** * 定义直线的类*/
public class Line
{
    public Point a;
    public Point b;
    public Point direct;
    public Line()   /** * 通过两点和方向构造直线*/
      {}
    public Line(int direct,Point a,Point b)
      {
         this.direct=direct;
         this.a=a;
         this.b=b;
      }           
}
package kyodai.map;
import java.awt.Poimt;
import java.util.Vector;
import java.util.Random;/** * 生成连连看方块的类*/
public class Map
{
    private int level;
    private int map[][];
    int array[];
    private int restBlock;
    private Vector bector;
    AnimateDelete animate;
    private boolean test;
    public Map()
      {
         level=28;
         map=new int[10][17];
         array=new int[170];
         restBlock=level*4;
         vector=new Vwctor();
         test=false;
         initMap();
      }
    public Map(int level)
      {
         this.level=28;
         map=new int[10][17];
         array=new int[170];
         restBlock=this.level*4;
         vector=new Vwctor();
         test=false;
         initMap();
      }
    public void SetTest(boolean test)
      {
          this.test=test;
      }
    public void SetTest(int level)
      {
          this.level=level;
          restBlock=level*4;
          initMap();
      }
    private void initMap()
      {
         for(int i=0;i<level;i++)
            {
                array[i*4]=i+1;
                array[i*4+1]=i+1;
                array[i*4+2]=i+1;
                array[i*4+3]=i+1;
            }
         random(array);
         for(int i=0;i<10;i++)
            {
                for(intj=0;j<17;j++)
                    map[i][j]=array[i*17+j];
            }
      }
    private void random(int array[])
      {
         Random random=new Random();
         for(int i=array.length;i>0;i--)
            {
                int j=random.nextInt(i);
                int temp=array[j];
                array[j]=array[i-1];
                array[i-1]=temp;
            }
      }
   public void earse(Piont a,Point b)
      {
          return restBlock<=0?0:restBlock;
      }
   public void refresh()
      {
          int count=getCount();
          if(count<=0)
             return;
          int temp[]=new int[count];
          count=0;
          for(int row=0;row<10;row++)
             {
                 for(int col=0;col<17;col++)
                    if(map[row][col]>0)
                       {
                           temp[count]=map[row][col];
                           count++;
                       }
             }
           random(temp);
           count=0;
           for(int row=0;row<10;row++)
             {
                 for(int col=0;col<17;col++)
                    if(map[row][col]>0)
                       {
                           map[row][col]=temp[count];
                           count++;
                       }
             }
          private boolean horizon(Point a,Point b,boolean recorder)
             {
                 if(a.x==b.x&&a.y==b.y)
                    return false;
                 int x_start=a.y<=b.y?a.y:b.y;
                 int x_end=a.y<=b.y?b.y:a.y;
                 for(int x=x_start+1;x<x_end;x++)
                   if(map[a.x][x]!=0)
                      return false;
                 if(!test&&recorder)
                    animate=new AnimateDelete(1,a,b);
                  return true;
              }
           private boolean vertical(Point a,Point b,boolean recorder)
              {
                 if(a.x==b.x&&a.y==b.y)
                    return false;
                 int y_start=a.x<=b.x?a.x:b.x;
                 int y_end=a.x<=b.x?b.x:a.x;
                 for(int y=y_start+1;y<y_end;y++)
                   if(map[y][a.y]!=0)
                      return false;
                 if(!test&&recorder)
                    animate=new AnimateDelete(0,a,b);
                  return true;
              }
          private boolean oneCorner(Point a,Point b)
              {
                  Point c=new Point(a.x,b.y);
                  Point d=new Point(b.x,a.y);
                  if(map[c.x][c.y]==0)
                     {
                         boolean method1=horizon(a,c,false)&&vertical(b,c,false);
                         if(method1)
                            {
                                if(!test)
                                   animate=new AnimateDelete(1,a,c,b);
                                return method1;
                            }
                     }
                  if(map[d.x][d.y]==0)
                     {
                  boolean meathod2=vertical(a,d,false)&&horizon(b,d,false);
                  if(method2&&!test)
           animate=new AnimateDelete(0,a,d,b);
                         return method2;
                     }
                  else
                     {
                   Return method2;
                     }
                }
            private Vector scan(Point a,Point b)
                {
             Vector v=new Vector();
             Point c=new Point(a.x,b.y);
             Point d=new Point(b.x,a.y);
             for(int y=a.y;y>=0;y--)
             if(map[a.x][y]==0&&map[b.x][y]==0 && vertical(new Point(a.x,y),new Point(b.x,y),false ))
             v.add(new Line(0,new Point(a.x,y),new Point(b.x,y)));
             for(int y=a.y;y<17;y++)
             if(map[a.x][y]==0&&map[b.x][y]==0 && Vertical(new Point(a.x,y),new Point(b.x,y),false ))
             v.add(new Line(0,new Point(a.x,y),new Point(b.x,y)));
             for(int x=a.x;x>=0;x--)
             if(map[x][a.y]==0&&map[x][b.y]==0 && horizon(new Point(x,a.y),new Point(x,b.y),false ))
             v.add(new Line(1,new Point(x,a.y),new Point(x,b.y)));
             for(int x=a.x;x<10;x++)
                       if(map[x][a.y]==0&&map[x][b.y]==0 && horizon(new Point(x,a.y),new Point(x,b.y),false ))
                   v.add(new Line(1,new Point(x,a.y),new Point(x,b.y)));
                    return v;
                }
             private boolean twoCorner(Point a,Point b)
                {
            vector =scan(a,b);
                   if(vector.isEmpty())
                   return false;
                   for(int index =0;index<Vector.size();index++)
                      {
                         Line line=(Line)vector.elementAt(index);
                         if(line.direct==1)
                            {
                               if(vertical(a,line.a,false)&&vertical(b,line.b,false))
                                  {
                                     if(!test)
                                        animate=new AnimateDelete(0,a,line.a,line.b,b);
                                     return true;
                                  }
                            }
                         else if(horizon(a,line.a,false)&&horizon(b,line.b,false))
                            {
                               if(!test)
                                 animate=new AnimateDelete(1,a,line.a,line.b,b);
                               return true;
                            }
                      }
                   return false;
                }
              public boolean test(Point a,Point b)
                {
                   if(map[a.x][a.y]!=map[b.x][b.y])
                      return false;
                   if(a.x==b.x&&horizon(a,b,true))
                      return true;
                   if(a.y==b.y&&vertical(a,b,true))
                      return true;
                   if(oneCorner(a,b))
                      return true;
                   else
                      return teoCorner(a,b)
                }
               public Line findNext(Point a)
                {
                   Point b=new Point();
                   a=findFirst(a);
                   if(a.equals(new Point(-1,-1)))
                     return new Line(0,a,b);
                   for(;!a.equals(new Point(-1,-1));a=findFirst(a))
                      for(b=findSwcond(a,b);!b.equals(new Point(-1,-1));b=findFirst(a))
                         if(test(a,b))
                            return new Line(1,a,b);
                    return new Line(0,a,b);
                }
               private Point findFirst(Point a)
                 {
                    int offset=0;
                    if(a!=null)
                      offset=a.x*17+a.y;
                    if(offset<0)
                      offset=-1;
                    for(int x=offset+1;x<170;x++)
                       {
                          int row=Math.round(x/17);
                          int col=x-row*17;
                          if(map[row][col]!=0)
                             return new Point(row,col);
                          www.(Point a,Point b)
                          {
                             if(a==null)
                               return new Point(-1,-1);
                             if(a.x+a.y<0)
                               return new Point(-1,-1);
                             if(b==null)
                               return new Point(0,0);
                             int ofset=Math.max(a.x*17+a.y,b.x*17+b.y);
                             for(int x=offset+1;x<170;x++)
                                {
                                   int row=Math.round(x/17);
                                   int col=x-row*17;
                                   if(map[row][col]==map[a.x][a.y])
                                     return new Point(row,col);
                                }
                            return new Point(-1,-1);
                          }
                       }
                   public int[][] getMap()
                     {
                        return map;
                     }
                 }
             }
      }
}



package kyodai.map;
import java.awt.Poimt;/** * 定义直线的类*/
public class Line
{
    public Point a;
    public Point b;
    public Point direct;
    public Line()   /** * 通过两点和方向构造直线*/
      {}
    public Line(int direct,Point a,Point b)
      {
         this.direct=direct;
         this.a=a;
         this.b=b;
      }           
}
package kyodai.map;
import java.awt.Poimt;
import java.util.Vector;
import java.util.Random;/** * 生成连连看方块的类*/
public class Map
{
    private int level;
    private int map[][];
    int array[];
    private int restBlock;
    private Vector bector;
    AnimateDelete animate;
    private boolean test;
    public Map()
      {
         level=28;
         map=new int[10][17];
         array=new int[170];
         restBlock=level*4;
         vector=new Vwctor();
         test=false;
         initMap();
      }
    public Map(int level)
      {
         this.level=28;
         map=new int[10][17];
         array=new int[170];
         restBlock=this.level*4;
         vector=new Vwctor();
         test=false;
         initMap();
      }
    public void SetTest(boolean test)
      {
          this.test=test;
      }
    public void SetTest(int level)
      {
          this.level=level;
          restBlock=level*4;
          initMap();
      }
    private void initMap()
      {
         for(int i=0;i<level;i++)
            {
                array[i*4]=i+1;
                array[i*4+1]=i+1;
                array[i*4+2]=i+1;
                array[i*4+3]=i+1;
            }
         random(array);
         for(int i=0;i<10;i++)
            {
                for(intj=0;j<17;j++)
                    map[i][j]=array[i*17+j];
            }
      }
    private void random(int array[])
      {
         Random random=new Random();
         for(int i=array.length;i>0;i--)
            {
                int j=random.nextInt(i);
                int temp=array[j];
                array[j]=array[i-1];
                array[i-1]=temp;
            }
      }
   public void earse(Piont a,Point b)
      {
          return restBlock<=0?0:restBlock;
      }
   public void refresh()
      {
          int count=getCount();
          if(count<=0)
             return;
          int temp[]=new int[count];
          count=0;
          for(int row=0;row<10;row++)
             {
                 for(int col=0;col<17;col++)
                    if(map[row][col]>0)
                       {
                           temp[count]=map[row][col];
                           count++;
                       }
             }
           random(temp);
           count=0;
           for(int row=0;row<10;row++)
             {
                 for(int col=0;col<17;col++)
                    if(map[row][col]>0)
                       {
                           map[row][col]=temp[count];
                           count++;
                       }
             }
          private boolean horizon(Point a,Point b,boolean recorder)
             {
                 if(a.x==b.x&&a.y==b.y)
                    return false;
                 int x_start=a.y<=b.y?a.y:b.y;
                 int x_end=a.y<=b.y?b.y:a.y;
                 for(int x=x_start+1;x<x_end;x++)
                   if(map[a.x][x]!=0)
                      return false;
                 if(!test&&recorder)
                    animate=new AnimateDelete(1,a,b);
                  return true;
              }
           private boolean vertical(Point a,Point b,boolean recorder)
              {
                 if(a.x==b.x&&a.y==b.y)
                    return false;
                 int y_start=a.x<=b.x?a.x:b.x;
                 int y_end=a.x<=b.x?b.x:a.x;
                 for(int y=y_start+1;y<y_end;y++)
                   if(map[y][a.y]!=0)
                      return false;
                 if(!test&&recorder)
                    animate=new AnimateDelete(0,a,b);
                  return true;
              }
          private boolean oneCorner(Point a,Point b)
              {
                  Point c=new Point(a.x,b.y);
                  Point d=new Point(b.x,a.y);
                  if(map[c.x][c.y]==0)
                     {
                         boolean method1=horizon(a,c,false)&&vertical(b,c,false);
                         if(method1)
                            {
                                if(!test)
                                   animate=new AnimateDelete(1,a,c,b);
                                return
                            }
                     }
              }
      }
}


package kyodai.map;
import java.awt.*;
import javax.swing.*;
import kyodai.*;
/* *消除连连看方块的类*/
public class AnimateDelete implements Runnable
{
    static JButton[]dots;
    static long delay=201;
    int []array=new int[44];//最大距离只可能为2行1列
    private int count=0;
    private volatile Thread thread;
    public AnimateDelete(JButton[]dots)
    {
       this.dots=dots;
       array=new int[0];
     }
       /**初始化*/
    public AnimateDelete(int direct,point a,point b)
    {
        initArray();
        calcTwoPoint(direct,a,b);
        start();
    }
     /**direct方向:1表示a,b在同一条直线上,b,c在同一竖线上:0表示a,b在同一竖线上,b,c在同一直线上*/
    public AnimateDelete(int direct,point a,point b,point c)
    {
         initArray();
         if(direct==1)      //先横后竖
           {
               calcTwoPoint(1,a,b);
               count--;
               calcTwoPoint(0,a,b);
           }
         else
           {
               calcTwoPoint(0,a,b);
               count--;
               calcTwoPoint(1,a,b);
           }
         start();
    }
    /**direct方向,1表示a,b在同横线上,b,c在同一竖线上,c,d为横线:0表示a,b在同一竖线上,b,c在同一直线上,c,d为竖线*/
    public AnimateDelete(int direct,point a,point b,point c,point d)
    {
         initArray();
         if(direct==1)      //横,竖,横方式处理         
         {
               calcTwoPoint(1,a,b);
               count--;
               calcTwoPoint(0,b,c);
               count--;
               calcTwoPoint(1,c,d);
           }
         else          //竖横竖方式处理
           {
               calcTwoPoint(0,a,b);
               count--;
               calcTwoPoint(1,b,c);
               count--;
               calcTwoPoint(0,c,d);
           }
         start();
    }
    /**计算消除的两点*/
    private void calcTwoPoint(int direct,point a,point b)
    {
        int offset=0;
        if(direct==1)      //横向连接
          {
              if(a.y>b.y)       //a点向b点是从右向左在水平线上消除
                 {
                     for(int y=a.y;y>=b.y;y--)
                         {
                             offset=a.x*Setting.COLUMN+y;
                             array[count]=offset;
                             count++;
                         }
                 }
               else             //a点向b点是从左向右在水平线上消除
                   {
                     for(int y=a.y;y<=b.y;y++)
                         {
                             offset=a.x*Setting.COLUMN+y;
                             array[count]=offset;
                             count++;
                         }
                 }
          }
       else
          {
             if(a.x>b.x)         //a点向b点是从下向上垂直消除
                 {
                    for(int x=a.x;x>=b.x;x--)
                       {
                          offset=x*Seting.COLUMN+a.y;
                          array[count]=offset;
                          count+;
                       }
                 }
              else           //a点向b点是从上向下垂直消除
                 {
                    for(int x=a.x;x<=b.x;x++)
                       {
                          offset=x*Seting.COLUMN+a.y;
                          array[count]=offset;
                          count+;
                       }
                 }
          }
     }
          /***设置动画速度*/
     public void SetSpeed(int speed)
     {
         delay=speed*10;
     }
     private void initArray()
    {
         if(array==null||array.length==0)
            {
                return;
            }       www.
     }
     public void test()
     {
         if(array==null||array.length==0)
            {
                return;
            }
          for(int i=0;i<array.length;i++)
             {
                 if(array[i]!=-1)
                    {
                       message("["+array[i]+"]");
                    }
             }
          System.out.println();
      }
      public void start()
      {
          thread=new Thread(this);
          thread.start();
      }
      public void run()
      {
          if(count<2)
            {
                return;
            }
          Thread currentThread=Thread currentThread();
          boolean animate=true;
          while(thread==currentThread&&animate)
            {
               for(int i=1;i<count-1;i++)
                  {
                      dots[array[i]].setEnabled(true);
                      dots[array[i]].setIcon(kyodai.Guidelcon);
                      try
                      {
                          thread.sleep(delay);
                      }
                     catch(InterruptedException ex)
                         {}
                  }
                for(int i=1;i<count-1;i++)
                  {
                      dots[array[i]].setIcon(null);
                      dots[array[i]].setEnabled(false);
                      try
                      {
                          thread.sleep(delay);
                      }
                     catch(InterruptedException ex)
                         {}
                   }
              dots[array[0]].setIcon(null);
              dots[array[0]].setEnabled(false);
              dots[array[array-1]].setIcon(null);
              dots[array[array-1]].setEnabled(false);
              animate=false;
           }
        stop();
      }
    public void stop()
      {
         if(thread!=null)
            {
                thread=null;
            }
      }
   void message(String str)
      {
           System.out.println(str);
      }      
}  
搜索更多相关主题的帖子: package private thread public direct 
2010-04-18 22:18
yukun314
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:35
专家分:120
注 册:2010-4-18
收藏
得分:0 
代码我都明白,但是就是运行出来什么都没有,应该是缺少图片,我不会添加,试了好多都不行,谢谢大虾们能帮帮我!
2010-04-18 22:21
快速回复:打下们帮我找一下这个程序的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032602 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved