forked from jvondermarck/dinosaur-exploder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameSettings.java
69 lines (61 loc) · 1.79 KB
/
GameSettings.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.dinosaur.dinosaurexploder.model;
public class GameSettings {
// Declare private static instance of the class
private static GameSettings instance;
// Global variables
private int difficultyLevel;
private Difficulty difficulty;
// Private constructor to prevent instantiation from other classes
private GameSettings() {
difficultyLevel = 1;
difficulty = createDifficulty();
}
private Difficulty createDifficulty() {
double speed, min, max;
switch (difficultyLevel) {
case 1:
speed = 1.0;
min = 90;
max = 90;
break;
case 2:
speed = 2.0;
min = 90;
max = 90;
break;
case 3:
speed = 2.5;
min = 90;
max = 90;
break;
case 4:
speed = 2.5;
min = 22.5;
max = 112.5;
break;
case 5:
speed = 3.0;
min = 45;
max = 135;
break;
default:
throw new IllegalArgumentException("Unknown difficulty level!");
}
return new Difficulty(speed, min, max);
}
// Public static method to provide access to the instance
public static GameSettings getInstance() {
if (instance == null) {
instance = new GameSettings();
}
return instance;
}
// Getters and setters for the global variables
public Difficulty getDifficulty() {
return difficulty;
}
public void setDifficultyLevel(int level) {
this.difficultyLevel = level;
difficulty = createDifficulty();
}
}