以下是一个简单的 Java 俄罗斯方块游戏代码示例,其中包括显示最高分和历史分数的功能: ```java import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JOptionPane; public class TetrisGame { private int currentScore; private int highestScore; private List<Integer> historyScores; public TetrisGame() { currentScore = 0; highestScore = 0; historyScores = new ArrayList<>(); } public void playGame() { // 游戏逻辑 // 假设每消除一行得 10 分 currentScore += 10; if (currentScore > highestScore) { highestScore = currentScore; } historyScores.add(currentScore); } public void showScores() { String message = "最高分: " + highestScore + "\n历史分数:\n"; for (int score : historyScores) { message += score + "\n"; } JOptionPane.showMessageDialog(new JFrame(), message); } public static void main(String[] args) { TetrisGame game = new TetrisGame(); game.playGame(); game.showScores(); } } ``` 这只是一个非常简单的示例,实际的俄罗斯方块游戏需要更复杂的图形界面和游戏逻辑处理。在这个示例中,`playGame` 方法模拟了游戏得分的增加,`showScores` 方法用于显示最高分和历史分数。 [2024-11-12 16:14:38 | AI写代码神器 | 358点数解答]