This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameController.java
46 lines (42 loc) · 1.77 KB
/
GameController.java
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
package ldts.dino.controller.game;
import ldts.dino.Application;
import ldts.dino.controller.Controller;
import ldts.dino.controller.game.elements.DinoController;
import ldts.dino.controller.game.elements.MotionController;
import ldts.dino.gui.GUI;
import ldts.dino.model.game.Game;
import ldts.dino.utils.SoundManager;
public class GameController extends Controller<Game> {
private final ElementsFactory elementsFactory;
private final MotionController motionController;
private final DinoController dinoController;
private final CollisionController collisionController;
public GameController(Game model) {
super(model);
this.elementsFactory = new ElementsFactory(model);
this.dinoController = new DinoController(model);
this.motionController = new MotionController(model);
this.collisionController = new CollisionController(model);
}
@Override
public void step(Application application, GUI.ACTION action, long time) {
switch (action) {
case QUIT:
application.exit();
break;
case BOMB:
if (getModel().getBombs() != 0 && !getModel().getObstacles().isEmpty()) {
SoundManager.getInstance().playBombSound();
getModel().removeBomb();
getModel().setExplosion(getModel().getObstacles().get(0).getPosition());
getModel().getObstacles().remove(0);
}
break;
}
getModel().setScore((float) (getModel().getScore() + 0.5));
elementsFactory.step();
motionController.step(application, action, time);
dinoController.step(application, action, time);
collisionController.step(application, action, time);
}
}