English 中文(简体)
如何使用透镜。 • 睡觉,显示简单的 dropping缩吗?
原标题:How to use Thread.sleep to show simple dropping animation?

I am making a game board and i would like to show the game board animation, The animation is a object dropping down like this,


time=0
○○○
○○○
○○○
○○○
time=1
●○○
○○○
○○○
○○○
time=2
●○○
●○○
○○○
○○○
time=3
●○○
●○○
●○○
○○○
time=4
●○○
●○○
●○○
●○○


 for (int row = 0; row < ROW_MAX; row++) {
      for (int col = 0; col < COLUMN_MAX; col++) {
          TempBoard[row][col]= hollow;
       }
 }
drawBoard(TempBoard);
Thread.sleep(1000);
TempBoard[0][column] = solid;
drawBoard(TempBoard);
Thread.sleep(1000);
TempBoard[1][column] = solid;
drawBoard(TempBoard);
Thread.sleep(1000);
TempBoard[2][column] = solid;
drawBoard(TempBoard);
Thread.sleep(100);
TempBoard[3][column] = solid;
drawBoard(TempBoard);
Thread.sleep(1000);

But i cannot get what i want,it shows time=4 directly and missed the steps in time=0-3 what is the problem? How can i fix it? Or any other simple way to do it? Thankyou.
The drawBoard method:

public void drawBoard(Disc[][] updateBoard) {
    Disc[][] tempBoard = updateBoard;
    for (int row = 0; row < ROW_MAX; row++) {
        for (int col = 0; col < COLUMN_MAX; col++) {
            if (tempBoard[row][col] == hollow) {
                //jbtBoard[row][col].setIcon(hollowImg);
                System.out.println(hollow);
            } else if (tempDisc[row][col] == solid) {
                //jbtBoard[row][col].setIcon(solidImg);
                System.out.println(solid);
        }
    }
}

然而, 在实施守则时,产出就好像:


time=0,1,2,3
○○○
○○○
○○○
○○○
time=4
●○○
●○○
●○○
●○○


问题回答

如果你(在一次回击中)在问答机上这样做,程序将像你所说的那样,但是,在你的代码完成后,“国际调查”的透镜只能显示你给出的 draw,这实际上意味着显示第4版。

你们不应使用Thread.sleep()。

您应使用





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签