我写了一个简单的扫雷应用程序,我遇到了麻烦:
用户点击一个矿井,之后我想循环通过所有的矿井并爆炸'每个矿井,一次一个,事件之间延迟半秒。
这些周期工作正常,但所有的地雷都爆炸了#39;在周期结束时。
// a 9x9 GRID of buttons
for( row=0;row<maxrows;row++)// cycle though 9 rows
{
for( col=0;col<maxcols;col++)// cycle through 9 cols
{
if(squares[row][col].EState == EState.Mine)// if the grid at row col is a mine
{
DisplayTile(row,col,TileType.Mine);// show the mine
try
{
MediaPlayer mp = MediaPlayer.create(context, R.raw.explosion02);// make an explosion sound
mp.start();
} catch(Exception ex) {
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
//I would like the display and explosion to actually happen now before we get to the nect mine
try
{
Thread.sleep(500);
}
catch(Exception ex)
{
Log.d("test",ex.getMessage());
}
}
}
}