-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTetrisGameLauncher.java
More file actions
54 lines (44 loc) · 1.69 KB
/
Copy pathTetrisGameLauncher.java
File metadata and controls
54 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import core.Context;
public final class TetrisGameLauncher {
private TetrisGameLauncher() {
}
public static void launch() {
SwingUtilities.invokeLater(() -> {
TetrisWorld world = new TetrisWorld();
Context context = GameContextFactory.create(world);
TetrisGamePanel panel = new TetrisGamePanel(context, world);
JFrame frame = new JFrame("Blockfall");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
});
}
public static String runSmokeTest() {
TetrisWorld world = new TetrisWorld(new Random(11L));
Context context = GameContextFactory.create(world);
context.queueCommand(new TetrisActionCommand(world, TetrisAction.MOVE_LEFT));
context.queueCommand(new TetrisActionCommand(world, TetrisAction.ROTATE_CW));
context.queueCommand(new TetrisActionCommand(world, TetrisAction.HARD_DROP));
context.executeQueuedCommands();
for (int step = 0; step < 4; step++) {
context.queueCommand(world);
context.executeQueuedCommands();
}
return "Blockfall smoke test passed: score="
+ world.getScore()
+ " lines="
+ world.getLinesCleared()
+ " level="
+ world.getLevel()
+ " gameOver="
+ world.isGameOver()
+ " next="
+ world.getNextType().name();
}
}