-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControllerState.java
48 lines (36 loc) · 1.11 KB
/
ControllerState.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
47
48
package chess.controller.state;
import com.googlecode.lanterna.input.KeyStroke;
import com.googlecode.lanterna.input.KeyType;
import com.googlecode.lanterna.screen.Screen;
import chess.model.Model;
import chess.view.View;
import java.io.IOException;
public abstract class ControllerState<T extends Model,W extends View<T>> {
T model;
W view;
ControllerState(T menuModel, W menuView) {
this.model = menuModel;
this.view = menuView;
}
protected ControllerState() {
}
protected void draw() throws IOException {
view.draw();
}
protected ControllerState<?,?> closeIfMoving(ControllerState<?,?> nextState) throws IOException {
if (nextState != this)
this.getView().close();
return nextState;
}
public KeyType getKey(Screen screen) throws IOException {
KeyStroke key;
key = screen.pollInput();
if (key == null)
return KeyType.Unknown;
return key.getKeyType();
}
public View<?> getView() {
return view;
}
public abstract ControllerState<?,?> run() throws IOException;
}