FindAroundMineNumber.java
上传用户:penghbff
上传日期:2007-04-16
资源大小:32k
文件大小:2k
源码类别:

射击游戏

开发平台:

Java

  1. import java.awt.Color;
  2. import javax.swing.Icon;
  3. import javax.swing.ImageIcon;
  4. public class FindAroundMineNumber
  5. {
  6.   Icon 周围无雷的图标;
  7.   public FindAroundMineNumber()
  8.    {
  9.     周围无雷的图标=new ImageIcon("无雷.gif");
  10.    }
  11.   public void 设置周围的雷数(int i,int j,Block block[][],int 行数, int 列数)
  12.    {
  13.      int 雷数=0;
  14.      if(block[i][j].判断是否是雷()==false)
  15.         { 
  16.            for(int k=Math.max(i-1,1);k<=Math.min(i+1,行数);k++)
  17.               { for(int t=Math.max(j-1,1);t<=Math.min(j+1,列数);t++)
  18.                   {
  19.                     if(block[k][t].判断是否是雷()==true)
  20.                        雷数++; 
  21.                   }
  22.               }
  23.            if(雷数>0)
  24.               { block[i][j].周围无雷=false;
  25.                 block[i][j].设置周围有雷时的名字(""+雷数);
  26.                 block[i][j].设置周围的雷数(雷数); 
  27.                 if(雷数==1)
  28.                     block[i][j].label.setForeground(Color.blue);
  29.                 if(雷数==2)
  30.                     block[i][j].label.setForeground(new Color(0,100,0));
  31.                 if(雷数==3)
  32.                     block[i][j].label.setForeground(Color.red);
  33.                 if(雷数>=4)
  34.                     block[i][j].label.setForeground(new Color(0,0,100));
  35.                   }
  36.            else
  37.               {  
  38.                 block[i][j].周围无雷=true;
  39.                 block[i][j].设置周围有雷时的名字("");
  40.                 block[i][j].设置周围的雷数(0); 
  41.                 block[i][j].设置周围无雷时的图标(周围无雷的图标);
  42.               }
  43.           
  44.         }
  45.   }