我这里有我的俄罗斯方块项目的代码片段。
private class Game implements Runnable {
private int numDropped = -1;
public void setCount(int count){
count++;
}
public int getCount(){
return count;
}
public void run() {
int column = 4, style = Piece.SHAPES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];
while (onPlay) {
if (piece != null) {
if (piece.isAlive()) {
try {
Thread.currentThread().sleep(100);
}
catch (InterruptedException ie) {
ie.printStackTrace();
}
continue;
}
}
checkFullLine();
if (isGameOver()) {
playItem.setEnabled(true);
pauseItem.setEnabled(true);
resumeItem.setEnabled(false);
rightPanel.setPlayButtonEnable(true);
rightPanel.setPauseButtonLabel(true);
displayGameOver();
return;
}
piece = new Piece(style, -1, column, board);
piece.start();
style = Piece.SHAPES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];
rightPanel.setTipStyle(style);
numDropped = numDropped+1;
RightPanel.scoreTextField.setText(numDropped+"");
}
}
}
顺便说一下,这个类Game
是一个内部类。每当一个新的部分下降时,numDropped
增量的值(如 JTextField 中显示的那样)但不久之后又回到零。我放错地方了吗
numDropped = numDropped+1;
RightPanel.scoreTextField.setText(numDropped+"");
? 或者因为其他的东西,比如存在之类的static
东西。请帮我。我是Java的新手。非常感谢你!