📄 sweepmine.java
字号:
//This class is about the search of the selected grid to show, when printing the left
// key of the mouse, it will view the content of the button, if the content is a empty, ok, it will
//search the grid’s around, if it find another empty grid, it will continue to search.
import java.awt.*;
public class SweepMine {
public void bfsSweeper ( ButtonMine[] button, int index ){
int firstX , firstY , seatX, seatY ;
int sizeX = 10, sizeY = 10;
int mineIndex , mineIndexNow;
int nowLength = 1 , newLength = 1, newBegin = 0 ;
int [] mineQueue = new int [ 1000 ];
button [ index ].setBackground(Color.gray);
firstX = button [ index ].x;
firstY = button [ index ].y ;
button [ index ].selectShow = true;
mineQueue [ 0 ] = index ;
int[][] move = new int[][]{
{-1,-1}, { 1, -1}, {0,-1}, {-1,0},
{0,1},{1,0},{1,1},{-1,1}};
for(;;){
for (int i = newBegin ; i < nowLength ; i ++ )
for (int j = 0 ; j < 8 ; j ++ )
{ mineIndex = mineQueue [ i ];
seatX = button [ mineIndex ].x + move [ j ] [ 0 ];
seatY = button [ mineIndex ].y + move [ j ] [ 1 ];
mineIndexNow = seatX * 10 + seatY ;
if ( seatX >=0 && seatX <sizeX && seatY >=0 && seatY < sizeY &&
button [ mineIndexNow ].selectShow ==false && button[mineIndexNow].markedMine==false )
{
button [ mineIndexNow ].selectShow = true;
if ( button [ mineIndexNow ].mineCounter == 0 && button [ mineIndexNow ].inButton==0 )
{ button [ mineIndexNow ].setBackground(Color.gray);
mineQueue [ newLength++ ] = mineIndexNow;}
else if ( button [ mineIndexNow ].inButton ==0 )
{ int mineNum = button [ mineIndexNow ].mineCounter;
char mineCh = (char) ( mineNum + 48 );
button [ mineIndexNow].setText(mineCh+"");}
}
}
if ( nowLength == newLength )
break;
else {
newBegin = nowLength;
nowLength = newLength;}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -