-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameState.java
More file actions
46 lines (35 loc) · 1.07 KB
/
GameState.java
File metadata and controls
46 lines (35 loc) · 1.07 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
import java.util.*;
public class GameState
{
private ArrayList<Screen> screens = new ArrayList<Screen>();
private int indexOfCurrentScreen = 0;
public GameState(int width, int height) {
//create all the screens
//Ex:
//screens.add(new WelcomeScreen(this, width, height));
//screens.add(new GameScreen(this, width, height));
//screens.add(new GameOverScreen(this, width, height));
screens.add(new WelcomeScreen(this, width, height));
screens.add(new GameScreen(this, width, height));
}
public Screen currentActiveScreen() {
return screens.get(indexOfCurrentScreen);
}
//methods that change which screen is currently showing
//public void switchTo*()...
//public void is*()...
public void switchToWelcomeScreen() {
indexOfCurrentScreen = 0;
screens.get(indexOfCurrentScreen).start();
}
public void switchToGameScreen() {
indexOfCurrentScreen = 1;
screens.get(indexOfCurrentScreen).start();
}
public boolean isWelcomeScreen() {
return indexOfCurrentScreen == 0;
}
public boolean isGameScreen() {
return indexOfCurrentScreen == 1;
}
}