-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
51 lines (42 loc) · 1.2 KB
/
Controller.java
File metadata and controls
51 lines (42 loc) · 1.2 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
import java.awt.event.*;
/**
* Controller class
* Listens to events, updates model and view
*
* @author Anton Samoilov, MSc SD <2459087S@student.gla.ac.uk> 2459087S
*/
public class Controller implements ActionListener {
private Model model;
private View view;
public Controller(Model model) {
this.model = model;
}
public void setView(View view) {
this.view = view;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.controlsPanel.spinButton) {
doSpin();
if (model.getGameEnded()) {
setEndGameControls();
}
}
if (e.getSource() == view.controlsPanel.newGameButton) {
startNewGame();
}
}
private void doSpin() {
model.spinCards();
view.updateView();
}
private void setEndGameControls() {
view.controlsPanel.newGameButton.setEnabled(true);
view.controlsPanel.spinButton.setEnabled(false);
}
private void startNewGame() {
view.controlsPanel.newGameButton.setEnabled(false);
view.controlsPanel.spinButton.setEnabled(true);
model.reset();
view.updateView();
}
}