-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsScreen.java
167 lines (131 loc) · 5.59 KB
/
SettingsScreen.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import greenfoot.Actor;
import greenfoot.Greenfoot;
import greenfoot.GreenfootImage;
import java.awt.Color;
import java.util.Arrays;
public class SettingsScreen extends Scene
{
private Difficulty easy;
private Difficulty medium;
private Difficulty hard;
private Theme space;
private Theme underwater;
private Button playButton;
private TextBanner banner;
private TypingMaster world;
private Button spaceThemeButton;
private Button underWaterThemeButton;
private Button easyLevelButton;
private Button mediumLevelButton;
private Button hardLevelButton;
private Button mainMenu;
public SettingsScreen() {
easy = new Easy();
medium = new Medium();
hard = new Hard();
space = new Space();
underwater = new Underwater();
banner = new TextBanner(new GreenfootImage(generateInfoButtonString(), 25, Color.BLACK, Color.WHITE));
playButton = new Button("Play");
spaceThemeButton = new Button("Space");
underWaterThemeButton = new Button("Ocean");
easyLevelButton = new Button("Easy");
mediumLevelButton = new Button("Medium");
hardLevelButton = new Button("Hard");
mainMenu = new Button("Main Menu");
playButton.setIsButton(true);
spaceThemeButton.setIsButton(true);
underWaterThemeButton.setIsButton(true);
easyLevelButton.setIsButton(true);
mediumLevelButton.setIsButton(true);
hardLevelButton.setIsButton(true);
mainMenu.setIsButton(true);
}
public void act()
{
// Reduce the number of times the data is process by executing only when a click is registered
if(Greenfoot.mouseClicked(null)) {
//System.out.println("In act");
// Change difficulty to Easy if it's been clicked on
if(Greenfoot.mouseClicked(easyLevelButton)) {
world.setDifficuly(easy);
}
// Change difficulty to Medium if it's been clicked on
if(Greenfoot.mouseClicked(mediumLevelButton)) {
world.setDifficuly(medium);
}
// Change difficulty to Hard if it's been clicked on
if(Greenfoot.mouseClicked(hardLevelButton)) {
world.setDifficuly(hard);
}
// Change Theme to Space if it's been clicked on
if(Greenfoot.mouseClicked(spaceThemeButton)) {
world.setTheme(space);
world.setBackground(world.getTheme().getBackground());
}
// Change Theme to Underwater if it's been clicked on
if(Greenfoot.mouseClicked(underWaterThemeButton)) {
world.setTheme(underwater);
world.setBackground(world.getTheme().getBackground());
}
// Change the Scene to the Game Screen
if(Greenfoot.mouseClicked(playButton)) {
world.setScene(world.getGameScreen());
}
if(Greenfoot.mouseClicked(mainMenu)) {
world.setScene(world.getMainMenu());
}
// Updates the Text
updateText();
}
}
/**
* Updates the text
*/
private void updateText() {
banner.setImage(new GreenfootImage(generateInfoButtonString(), 35, Color.WHITE, new Color(0,0,0,0)));
// banner.getImage().scale(6 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
}
public void enterScene() {
// Add actors to world
world = (TypingMaster) getWorld();
// Add Theme: Space
world.addObject(spaceThemeButton, 5, 4);
//space.getImage().scale(3 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
// Add Theme: Underwater
world.addObject(underWaterThemeButton, 5, 5);
//underwater.getImage().scale(3 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
// Add Difficulty: Easy
world.addObject(easyLevelButton, 11, 4);
//easy.getImage().scale(3 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
// Add Difficulty: Medium
world.addObject(mediumLevelButton, 11, 5);
//medium.getImage().scale(3 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
// Add Difficulty: Hard
world.addObject(hardLevelButton, 11, 6);
//hard.getImage().scale(3 * TypingGame.GRID_SIZE, 1 * TypingGame.GRID_SIZE);
// Add play game
world.addObject(playButton, 8, 3);
world.addObject(mainMenu, 8, 7);
//Greenfoot.delay(100);
//playButton.getImage().scale(4 * TypingGame.GRID_SIZE, 2 * TypingGame.GRID_SIZE);
//System.out.println("between two");
// Add Info To Screen
world.addObject(banner, 8, 2);
updateText();
}
public void exitScene() {
// Remove the objects from the world
world.removeObjects(Arrays.asList(new Actor[] {playButton, spaceThemeButton, underWaterThemeButton, easyLevelButton, mediumLevelButton, hardLevelButton, banner, mainMenu}));
}
private String generateInfoButtonString() {
if(world != null) {
String theme = world.getTheme().getClass().getName();
String difficulty = world.getDifficuly().getClass().getName();
return String.format("Theme=%-12s Difficulty=%-12s", theme.trim(), difficulty.trim());
}
else {
return "";
}
}
}