Skip to content

Commit 17d1399

Browse files
Merge branch 'main' into main
2 parents 7ecc87b + 4faff3c commit 17d1399

File tree

10 files changed

+188
-16
lines changed

10 files changed

+188
-16
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
<artifactId>maven-compiler-plugin</artifactId>
5858
<version>3.8.1</version>
5959
<configuration>
60-
<source>16</source>
61-
<target>16</target>
60+
<source>17</source>
61+
<target>17</target>
6262
</configuration>
6363
</plugin>
6464
<plugin>
@@ -70,7 +70,7 @@
7070
<!-- Default configuration for running with: mvn clean javafx:run -->
7171
<id>default-cli</id>
7272
<configuration>
73-
<mainClass>com.dinosaur.dinosaurexploder/com.dinosaur.dinosaurexploder.HelloApplication
73+
<mainClass>com.dinosaur.dinosaurexploder/com.dinosaur.dinosaurexploder.DinosaurApp
7474
</mainClass>
7575
<launcher>app</launcher>
7676
<jlinkZipName>app</jlinkZipName>

src/main/java/com/dinosaur/dinosaurexploder/DinosaurApp.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.almasb.fxgl.app.GameSettings;
77
import com.almasb.fxgl.dsl.FXGL;
88
import com.almasb.fxgl.entity.Entity;
9+
import com.almasb.fxgl.localization.Language;
910
import com.dinosaur.dinosaurexploder.controller.DinosaurController;
1011
import com.dinosaur.dinosaurexploder.model.EntityType;
1112
import com.dinosaur.dinosaurexploder.model.GameEntityFactory;
@@ -14,6 +15,9 @@
1415
import javafx.scene.input.KeyCode;
1516

1617
import static com.almasb.fxgl.dsl.FXGL.*;
18+
19+
import java.util.Locale;
20+
import java.util.ResourceBundle;
1721
/**
1822
* Summary :
1923
* The Factory handles the DinosaurApp,Physics,Settings and Input of all entities in the game
@@ -69,4 +73,19 @@ public static void main(String[] args) {
6973
launch(args);
7074

7175
}
76+
77+
@Override
78+
protected void onPreInit() {
79+
initLanguages();
80+
}
81+
82+
public static void initLanguages() {
83+
// Init languages
84+
getLocalizationService().addLanguageData(Language.ENGLISH, ResourceBundle.getBundle("assets.properties.texts", Locale.ENGLISH));
85+
getLocalizationService().addLanguageData(Language.GERMAN, ResourceBundle.getBundle("assets.properties.texts", Locale.GERMAN));
86+
87+
// Set first entry as default
88+
getLocalizationService().selectedLanguageProperty().unbind();
89+
getLocalizationService().setSelectedLanguage(Language.ENGLISH);
90+
}
7291
}

src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import javafx.scene.input.KeyCode;
88
import javafx.scene.paint.Color;
99
import javafx.scene.shape.Rectangle;
10-
1110
import static com.almasb.fxgl.dsl.FXGL.*;
1211
import static com.almasb.fxgl.dsl.FXGLForKtKt.spawn;
1312
import static javafx.util.Duration.seconds;
@@ -118,7 +117,7 @@ public void initPhysics() {
118117
* To detect whether the player lives are empty or not
119118
*/
120119
public void gameOver(){
121-
getDialogService().showConfirmationBox("Game Over. Play Again?", yes ->{
120+
getDialogService().showConfirmationBox(getLocalizationService().getLocalizedString("Game.2"), yes ->{
122121
if (yes){
123122
getGameController().startNewGame();
124123
} else {

src/main/java/com/dinosaur/dinosaurexploder/model/GameConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package com.dinosaur.dinosaurexploder.model;
2+
3+
import java.util.List;
4+
5+
import com.almasb.fxgl.localization.Language;
6+
27
/**
38
*
49
* This holds every constant in the the PROJECT
@@ -33,4 +38,7 @@ public class GameConstants {
3338

3439
public static final String GAME_NAME = "Dinosaur Exploder";
3540

41+
public static final List<Language> AVAILABLE_LANGUAGES = List.of(Language.ENGLISH, Language.GERMAN );
42+
43+
3644
}

src/main/java/com/dinosaur/dinosaurexploder/model/LifeComponent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.dinosaur.dinosaurexploder.model;
22

3+
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
4+
35
import com.almasb.fxgl.entity.component.Component;
46
import javafx.scene.Node;
57
import javafx.scene.image.Image;
@@ -17,7 +19,7 @@ public class LifeComponent extends Component implements Life {
1719
final private Image heart = new Image(GameConstants.HEART_IMAGEPATH);
1820
Integer life = 3;
1921
// Declaring Lives Text
20-
Text lifeText = new Text("Lives");
22+
Text lifeText = new Text(getLocalizationService().getLocalizedString("Game.5"));
2123

2224
// Declaring 3 Hearts
2325
ImageView test1 = new ImageView(heart);

src/main/java/com/dinosaur/dinosaurexploder/model/ScoreComponent.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.dinosaur.dinosaurexploder.model;
22

33

4-
import java.io.*;
4+
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
5+
6+
import java.io.FileInputStream;
7+
import java.io.FileOutputStream;
8+
import java.io.IOException;
9+
import java.io.ObjectInputStream;
10+
import java.io.ObjectOutputStream;
511

612
import com.almasb.fxgl.entity.component.Component;
713
import javafx.scene.image.Image;
@@ -50,8 +56,8 @@ public void onUpdate(double ptf) {
5056
entity.getViewComponent().clearChildren();
5157
GridPane gridPane = new GridPane();
5258
gridPane.setHgap(10);
53-
Text scoreText = new Text("Score: " + score.toString());
54-
Text highScoreText = new Text("HighScore: " + highScore.getHigh().toString());
59+
Text scoreText = new Text(getLocalizationService().getLocalizedString("Game.3") + score.toString());
60+
Text highScoreText = new Text(getLocalizationService().getLocalizedString("Game.4") + highScore.getHigh().toString());
5561
Image image = new Image(GameConstants.GREENDINO_IMAGEPATH,25,20,false, false);
5662
ImageView imageView = new ImageView();
5763
imageView.setImage(image);
@@ -99,6 +105,4 @@ public void incrementScore(int i){
99105
e.printStackTrace();
100106
}}
101107
}
102-
103-
104108
}

src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
package com.dinosaur.dinosaurexploder.view;
22

3+
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
4+
import static com.almasb.fxgl.dsl.FXGL.getSettings;
5+
6+
import java.util.Arrays;
7+
import java.util.Locale;
38
import com.almasb.fxgl.app.scene.FXGLMenu;
49
import com.almasb.fxgl.app.scene.MenuType;
510
import com.almasb.fxgl.dsl.FXGL;
11+
import com.almasb.fxgl.localization.Language;
12+
import com.almasb.fxgl.ui.FXGLChoiceBox;
613
import com.almasb.fxgl.ui.FontType;
14+
import com.dinosaur.dinosaurexploder.DinosaurApp;
715
import com.dinosaur.dinosaurexploder.model.GameConstants;
16+
import javafx.collections.FXCollections;
17+
import javafx.collections.ObservableList;
818
import javafx.scene.control.Button;
919
import javafx.scene.image.Image;
1020
import javafx.scene.image.ImageView;
1121
import javafx.scene.media.Media;
1222
import javafx.scene.media.MediaPlayer;
1323
import javafx.scene.paint.Color;
1424
import javafx.scene.shape.Rectangle;
25+
import javafx.scene.text.Text;
26+
import javafx.util.StringConverter;
1527

1628
import java.io.FileInputStream;
1729
import java.io.FileNotFoundException;
@@ -28,6 +40,7 @@ public DinosaurMenu() throws FileNotFoundException {
2840

2941
var bg = new Rectangle(getAppWidth(), getAppHeight(), Color.BLACK);
3042

43+
3144
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
3245
var startButton = new Button("Start Game");
3346
var quitButton = new Button("Quit");
@@ -86,4 +99,63 @@ public DinosaurMenu() throws FileNotFoundException {
8699
);
87100
}
88101

89-
}
102+
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
103+
title.setTranslateY(100);
104+
title.setTranslateX(getAppWidth() / 2 - 175);
105+
106+
DinosaurApp.initLanguages();
107+
drawControls(mainMenuSound, bg, title);
108+
}
109+
110+
private void drawControls(MediaPlayer mainMenuSound, Rectangle bg, Text title) {
111+
getContentRoot().getChildren().removeAll(getContentRoot().getChildren());
112+
113+
var startButton = new Button(getLocalizationService().getLocalizedString("Menu.1"));
114+
var quitButton = new Button(getLocalizationService().getLocalizedString("Menu.2"));
115+
var chooseLanguage = new FXGLChoiceBox<Language>(FXCollections.observableArrayList(GameConstants.AVAILABLE_LANGUAGES));
116+
117+
118+
startButton.setMinSize(200, 100);
119+
quitButton.setMinSize(200, 100);
120+
121+
startButton.setTranslateY(350);
122+
startButton.setTranslateX(getAppWidth() / 2 - 100);
123+
startButton.setStyle("-fx-font-size:20");
124+
125+
126+
quitButton.setTranslateY(490);
127+
quitButton.setTranslateX(getAppWidth() / 2 - 100);
128+
quitButton.setStyle("-fx-font-size:20");
129+
130+
chooseLanguage.setTranslateY(700);
131+
chooseLanguage.setTranslateX(getAppWidth() / 2 - 100);
132+
chooseLanguage.setValue(getLocalizationService().getSelectedLanguage());
133+
quitButton.setStyle("-fx-font-size:20");
134+
chooseLanguage.setConverter(new StringConverter<Language>() {
135+
136+
@Override
137+
public String toString(Language language) {
138+
return getLocalizationService().getLocalizedString(language.getName());
139+
}
140+
141+
@Override
142+
public Language fromString(String text) {
143+
throw new UnsupportedOperationException();
144+
}
145+
});
146+
147+
startButton.setOnAction(event -> {
148+
fireNewGame();
149+
mainMenuSound.stop();
150+
});
151+
152+
quitButton.setOnAction(event -> fireExit());
153+
154+
chooseLanguage.setOnAction(event -> {
155+
getLocalizationService().setSelectedLanguage(chooseLanguage.getValue());
156+
drawControls(mainMenuSound, bg, title);
157+
});
158+
159+
getContentRoot().getChildren().addAll(bg, title, startButton, quitButton, chooseLanguage);
160+
}
161+
}

src/main/java/com/dinosaur/dinosaurexploder/view/PauseMenu.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212
import javafx.scene.paint.Color;
1313
import javafx.scene.shape.Rectangle;
1414
import javafx.scene.text.Text;
15+
import static com.almasb.fxgl.dsl.FXGL.*;
1516

17+
import static com.almasb.fxgl.dsl.FXGL.getLocalizationService;
1618
import static com.almasb.fxgl.dsl.FXGLForKtKt.getUIFactoryService;
19+
20+
import com.dinosaur.dinosaurexploder.DinosaurApp;
1721
import com.dinosaur.dinosaurexploder.model.GameConstants;
1822

1923
public class PauseMenu extends FXGLMenu {
2024
public PauseMenu() {
2125
super(MenuType.GAME_MENU);
26+
DinosaurApp.initLanguages();
27+
2228

23-
PauseButton btnBack = new PauseButton("Back",() -> fireResume());
29+
PauseButton btnBack = new PauseButton(getLocalizationService().getLocalizedString("Pause.1"),() -> fireResume());
2430

25-
PauseButton btnQuitGame = new PauseButton("Quit Game",() -> fireExitToMainMenu());
31+
PauseButton btnQuitGame = new PauseButton(getLocalizationService().getLocalizedString("Pause.2"),() -> fireExitToMainMenu());
2632

27-
ControlButton btnControls = new ControlButton("Controls");
33+
ControlButton btnControls = new ControlButton(getLocalizationService().getLocalizedString("Pause.3"));
2834

2935
btnControls.setControlAction(() -> {
3036

@@ -33,7 +39,7 @@ public PauseMenu() {
3339
var controlsBox = new VBox(15);
3440

3541
controlsBox.getChildren().addAll(
36-
new PauseButton("Back", () -> {
42+
new PauseButton(getLocalizationService().getLocalizedString("Pause.4"), () -> {
3743
controlsBox.getChildren().removeAll(controlsBox.getChildren());
3844
removeChild(bg);
3945
btnBack.enable();
@@ -46,6 +52,12 @@ public PauseMenu() {
4652
new OptionsButton("← / A : Move spaceship left"),
4753
new OptionsButton("ESC: Pause the game"),
4854
new OptionsButton("SPACE: Shoot"));
55+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.5")),
56+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.6")),
57+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.7")),
58+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.8")),
59+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.9")),
60+
new OptionsButton(getLocalizationService().getLocalizedString("Pause.10")));
4961

5062
controlsBox.setTranslateX(300);
5163
controlsBox.setTranslateY(getAppWidth() / 2);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Menu
2+
Menu.1=Spiel starten
3+
Menu.2=Beenden
4+
5+
# Game
6+
Game.1=Punkte
7+
Game.2=Game Over. Nochmal spielen?
8+
Game.3=Punkte:
9+
Game.4=Höchste Punktzahl:
10+
Game.5=Leben
11+
12+
# Pause
13+
Pause.1=Zurück
14+
Pause.2=Spiel beenden
15+
Pause.3=Steuerung
16+
Pause.4=Zurück
17+
Pause.5=\u2191: Raumschiff nach oben bewegen
18+
Pause.6=\u2193: Raumschiff nach unten bewegen
19+
Pause.7=\u2192: Raumschiff nach rechts bewegen
20+
Pause.8=\u2190: Raumschiff nach links bewegen
21+
Pause.9=ESC: Spiel pausieren
22+
Pause.10=LEERTASTE: Schießen
23+
24+
# Languages
25+
ENGLISH=Englisch
26+
GERMAN=Deutsch
27+
28+
# Dialog
29+
dialog.yes = JA
30+
dialog.no = NEIN
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Menu
2+
Menu.1=Start Game
3+
Menu.2=Quit
4+
5+
# Game
6+
Game.1=Score
7+
Game.2=Game Over. Play Again?
8+
Game.3=Score:
9+
Game.4=HighScore:
10+
Game.5=Lives
11+
12+
# Pause
13+
Pause.1=Back
14+
Pause.2=Quit Game
15+
Pause.3=Controls
16+
Pause.4=Back
17+
Pause.5=\u2191: Move spaceship up
18+
Pause.6=\u2193: Move spaceship down
19+
Pause.7=\u2192: Move spaceship right
20+
Pause.8=\u2190: Move spaceship left
21+
Pause.9=ESC: Pause the game
22+
PAUSE.10=SPACE: Shoot
23+
24+
# Languages
25+
ENGLISH=English
26+
GERMAN=German

0 commit comments

Comments
 (0)