Skip to content

Commit add9541

Browse files
main
2 parents 3158023 + 17d1399 commit add9541

File tree

12 files changed

+174
-127
lines changed

12 files changed

+174
-127
lines changed

dinosaur-exploder.iml

Lines changed: 0 additions & 47 deletions
This file was deleted.

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/DinosaurGUI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public void initSettings(GameSettings settings) {
2020
settings.setSceneFactory(new SceneFactory() {
2121
@Override
2222
public FXGLMenu newMainMenu() {
23-
return new DinosaurMenu();
23+
try {
24+
return new DinosaurMenu();
25+
} catch (FileNotFoundException e) {
26+
throw new RuntimeException(e);
27+
}
2428
}
2529

2630
@Override

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

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@
55
import com.almasb.fxgl.dsl.FXGL;
66
import com.almasb.fxgl.ui.FontType;
77
import com.dinosaur.dinosaurexploder.model.GameConstants;
8-
import javafx.collections.FXCollections;
98
import javafx.scene.control.Button;
10-
import javafx.scene.control.ChoiceBox;
119
import javafx.scene.image.Image;
1210
import javafx.scene.image.ImageView;
1311
import javafx.scene.media.Media;
1412
import javafx.scene.media.MediaPlayer;
1513
import javafx.scene.paint.Color;
1614
import javafx.scene.shape.Rectangle;
1715

18-
import java.io.File;
1916
import java.io.FileInputStream;
2017
import java.io.FileNotFoundException;
2118

2219
public class DinosaurMenu extends FXGLMenu {
2320

24-
public DinosaurMenu() {
21+
public DinosaurMenu() throws FileNotFoundException {
2522
super(MenuType.MAIN_MENU);
2623

2724
Media media = new Media(getClass().getResource(GameConstants.MAINMENU_SOUND).toExternalForm());
@@ -34,66 +31,59 @@ public DinosaurMenu() {
3431
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
3532
var startButton = new Button("Start Game");
3633
var quitButton = new Button("Quit");
37-
try {
38-
39-
FileInputStream fileInputStream = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png");
40-
FileInputStream mutemusic_button = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/silent.png");
41-
42-
// image for dino in main menu
43-
Image image = new Image(fileInputStream);
44-
ImageView imageView = new ImageView(image);
45-
imageView.setFitHeight(250);
46-
imageView.setFitWidth(200);
47-
imageView.setX(200);
48-
imageView.setY(190);
49-
imageView.setPreserveRatio(true);
50-
51-
//adding image to manually mute music
52-
53-
Image mute = new Image(mutemusic_button);
54-
ImageView imageView_mute = new ImageView(mute);
55-
imageView_mute.setFitHeight(40);
56-
imageView_mute.setFitWidth(50);
57-
imageView_mute.setX(490);
58-
imageView_mute.setY(20);
59-
imageView_mute.setPreserveRatio(true);
60-
61-
startButton.setMinSize(50, 50);
62-
quitButton.setMinSize(140, 50);
63-
64-
title.setTranslateY(100);
65-
title.setTranslateX(getAppWidth() / 2 - 145);
66-
67-
startButton.setTranslateY(400);
68-
startButton.setTranslateX(getAppWidth() / 2 - 50);
69-
startButton.setStyle("-fx-font-size:20");
70-
71-
quitButton.setTranslateY(500);
72-
quitButton.setTranslateX(getAppWidth() / 2 - 50);
73-
quitButton.setStyle("-fx-font-size:20");
74-
75-
startButton.setOnAction(event -> {
76-
fireNewGame();
77-
mainMenuSound.stop();
78-
});
79-
80-
imageView_mute.setOnMouseClicked(mouseEvent -> {
81-
mainMenuSound.stop();
82-
});
83-
84-
imageView_mute.setOnMousePressed(mouseEvent -> {
85-
mainMenuSound.stop();
86-
});
87-
quitButton.setOnAction(event -> fireExit());
88-
89-
getContentRoot().getChildren().addAll(
90-
bg, title, startButton, quitButton, imageView, imageView_mute
91-
);
92-
93-
}
94-
catch (FileNotFoundException e){
95-
e.printStackTrace();
96-
}
34+
FileInputStream fileInputStream= new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png");
35+
FileInputStream mutemusic_button=new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/silent.png");
36+
37+
// image for dino in main menu
38+
Image image = new Image(fileInputStream);
39+
ImageView imageView = new ImageView(image);
40+
imageView.setFitHeight(250);
41+
imageView.setFitWidth(200);
42+
imageView.setX(200);
43+
imageView.setY(190);
44+
imageView.setPreserveRatio(true);
45+
46+
//adding image to manually mute music
47+
48+
Image mute = new Image(mutemusic_button);
49+
ImageView imageView_mute=new ImageView(mute);
50+
imageView_mute.setFitHeight(40);
51+
imageView_mute.setFitWidth(50);
52+
imageView_mute.setX(490);
53+
imageView_mute.setY(20);
54+
imageView_mute.setPreserveRatio(true);
55+
56+
startButton.setMinSize(50, 50);
57+
quitButton.setMinSize(140, 50);
58+
59+
title.setTranslateY(100);
60+
title.setTranslateX(getAppWidth() / 2 - 145);
61+
62+
startButton.setTranslateY(400);
63+
startButton.setTranslateX(getAppWidth() / 2 - 50);
64+
startButton.setStyle("-fx-font-size:20");
65+
66+
quitButton.setTranslateY(500);
67+
quitButton.setTranslateX(getAppWidth() / 2 - 50);
68+
quitButton.setStyle("-fx-font-size:20");
69+
70+
startButton.setOnAction(event -> {
71+
fireNewGame();
72+
mainMenuSound.stop();
73+
});
74+
75+
imageView_mute.setOnMouseClicked(mouseEvent -> {
76+
mainMenuSound.stop();
77+
});
78+
79+
imageView_mute.setOnMousePressed(mouseEvent -> {
80+
mainMenuSound.stop();
81+
});
82+
quitButton.setOnAction(event -> fireExit());
83+
84+
getContentRoot().getChildren().addAll(
85+
bg, title, startButton, quitButton,imageView,imageView_mute
86+
);
9787
}
9888

9989
}

0 commit comments

Comments
 (0)