-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
57 lines (45 loc) · 1.05 KB
/
Copy pathGame.java
File metadata and controls
57 lines (45 loc) · 1.05 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
55
56
57
public class Game {
private World world;
private boolean isOver;
private int level;
private Scene scene;
private Controller controller;
//create a new plaform game
public Game() {
this.isOver = false;
this.level = 0;
this.world = new World();
String[][] map = world.getLevel(level);
this.scene = new Scene(map);
Player player = scene.getPlayer();
this.controller = new Controller(player);
}
public void update() {
controller.update();
scene.update();
this.isOver = scene.isPlayerDead();
if (scene.getExit().isTouching(scene.getPlayer() ) ) {
this.level++;
if (this.level < world.getLength() ) {
String[][] map = world.getLevel(this.level);
this.scene = new Scene(map);
this.controller = new Controller(this.scene.getPlayer() );
}
else {
this.isOver = true;
}
}
}
public void render() {
scene.draw();
StdDraw.show(10);
}
//the main game loop
public static void main (String[] args) {
Game game = new Game();
while (game.isOver == false) {
game.update();
game.render();
}
}
}