Skip to content

Commit dbd2935

Browse files
committed
Merge branch 'main' into fork/Johann4002herti/main
# Conflicts: # src/main/java/com/dinosaur/dinosaurexploder/utils/ShipUnlockChecker.java # src/main/java/com/dinosaur/dinosaurexploder/utils/WeaponUnlockChecker.java
2 parents c3a2f90 + bf3ef80 commit dbd2935

21 files changed

+774
-379
lines changed

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
<version>${junit.version}</version>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>org.mockito</groupId>
42+
<artifactId>mockito-core</artifactId>
43+
<version>5.17.0</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.mockito</groupId>
48+
<artifactId>mockito-inline</artifactId>
49+
<version>5.2.0</version>
50+
<scope>test</scope>
51+
</dependency>
4052
<dependency>
4153
<groupId>one.jpro</groupId>
4254
<artifactId>jpro-webapi</artifactId>
@@ -99,7 +111,8 @@
99111
<createDependencyReducedPom>false</createDependencyReducedPom>
100112
<transformers>
101113
<!-- Add Main-Class to the manifest -->
102-
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
114+
<transformer
115+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
103116
<mainClass>${mainClassName}</mainClass>
104117
</transformer>
105118
</transformers>

src/main/java/com/dinosaur/dinosaurexploder/components/BombComponent.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,27 @@ public class BombComponent extends Component implements Bomb {
2424
private int bombCount = 3;
2525
private int maxBombCount = 3;
2626
private Image spcshpImg;
27-
27+
private int selectedShip;
28+
2829
// Tracking variables for regeneration
2930
private int lastLevel = 1;
3031
private int coinCounter = 0;
3132
private static final int COINS_NEEDED_FOR_BOMB = 15; // Number of coins needed to regenerate a bomb
32-
33+
3334
public BombComponent() {
3435
// Selected spaceship from GameData
35-
int selectedShip = GameData.getSelectedShip();
36+
this.selectedShip = GameData.getSelectedShip();
3637

3738
// Set the image of SelectedShip using the spaceship number
38-
if (selectedShip != 0) {
39-
String shipImagePath = "/assets/textures/spaceship" + selectedShip + ".png";
40-
System.out.println("Selected spaceship: " + selectedShip);
41-
this.spcshpImg = new Image(shipImagePath);
42-
}
39+
4340
}
4441

45-
46-
// Declaring Bomb Text
47-
private Image bomb = new Image(GameConstants.BOMB_IMAGE_PATH);
4842
// Declaring 3 Bomb
49-
ImageView bomb1 = new ImageView(bomb);
50-
ImageView bomb2 = new ImageView(bomb);
51-
ImageView bomb3 = new ImageView(bomb);
52-
private Text bombText = new Text("Bombs Left: " + bombCount);
43+
ImageView bomb1;
44+
ImageView bomb2;
45+
ImageView bomb3;
46+
// Declaring Bomb Text
47+
private Text bombText;
5348

5449

5550
private Node bombUI;
@@ -58,6 +53,11 @@ public BombComponent() {
5853

5954
@Override
6055
public void onAdded() {
56+
Image bomb = new Image(GameConstants.BOMB_IMAGE_PATH);
57+
bomb1 = new ImageView(bomb);
58+
bomb2 = new ImageView(bomb);
59+
bomb3 = new ImageView(bomb);
60+
6161
// Initialize bombText with the translated string
6262
bombText = new Text(languageManager.getTranslation("bombs_left") + ": " + bombCount);
6363

@@ -86,6 +86,7 @@ private void updateTexts() {
8686

8787
/**
8888
* This method creates the UI for displaying the bomb count and bomb images.
89+
*
8990
* @return Node - The created bomb UI node
9091
*/
9192
private Node createBombUI() {
@@ -106,16 +107,17 @@ private Node createBombUI() {
106107
/**
107108
* Updates the bomb UI based on the current bomb count.
108109
*/
109-
private void updateBombUI() {
110+
protected void updateBombUI() {
110111
bomb1.setVisible(bombCount >= 1);
111112
bomb2.setVisible(bombCount >= 2);
112113
bomb3.setVisible(bombCount >= 3);
113114
// Update bomb text with the remaining bombs
114115
bombText.setText(languageManager.getTranslation("bombs_left") + ": " + bombCount);
115116
}
117+
116118
/**
117119
* Summary:
118-
* This method returns the current number of bombs.
120+
* This method returns the current number of bombs.
119121
*/
120122
@Override
121123
public int getBombCount() {
@@ -124,9 +126,9 @@ public int getBombCount() {
124126

125127
/**
126128
* Summary :
127-
* This method is used to launch a row of bullets as a bomb.
129+
* This method is used to launch a row of bullets as a bomb.
128130
* Parameters :
129-
* Entity player - The player entity using the bomb
131+
* Entity player - The player entity using the bomb
130132
*/
131133
@Override
132134
public void useBomb(Entity player) {
@@ -138,15 +140,23 @@ public void useBomb(Entity player) {
138140
System.out.println("No bombs left!");
139141
}
140142
}
143+
141144
/**
142145
* Summary :
143-
* This method spawns a row of bullets from the player's position.
146+
* This method spawns a row of bullets from the player's position.
144147
* Parameters :
145-
* Entity player - The player entity from which to spawn the bullets
148+
* Entity player - The player entity from which to spawn the bullets
146149
*/
147-
private void spawnBombBullets(Entity player) {
150+
protected void spawnBombBullets(Entity player) {
148151
Point2D center = player.getCenter();
149152
Image projImg = new Image(GameConstants.BASE_PROJECTILE_IMAGE_PATH);
153+
154+
if (selectedShip != 0) {
155+
String shipImagePath = "/assets/textures/spaceship" + selectedShip + ".png";
156+
System.out.println("Selected spaceship: " + selectedShip);
157+
this.spcshpImg = new Image(shipImagePath);
158+
}
159+
150160
for (int i = -5; i <= 5; i++) {
151161
double angle = entity.getRotation() - 90 + i * 10;
152162
Vec2 direction = Vec2.fromAngle(angle);
@@ -155,11 +165,11 @@ private void spawnBombBullets(Entity player) {
155165
}
156166
System.out.println("Bomb used! " + getBombCount() + " bombs left!");
157167
}
158-
168+
159169
/**
160170
* Regenerates bombs when a new level is reached.
161171
* Call this method when the player advances to a new level.
162-
*
172+
*
163173
* @param currentLevel The current level of the game
164174
*/
165175
public void checkLevelForBombRegeneration(int currentLevel) {
@@ -170,7 +180,7 @@ public void checkLevelForBombRegeneration(int currentLevel) {
170180
System.out.println("Level up! Regenerated a bomb. Current bombs: " + bombCount);
171181
}
172182
}
173-
183+
174184
/**
175185
* Tracks coin collection and regenerates bombs when enough coins are collected.
176186
* Call this method whenever the player collects a coin.
@@ -184,14 +194,18 @@ public void trackCoinForBombRegeneration() {
184194
System.out.println("Collected " + COINS_NEEDED_FOR_BOMB + " coins! Regenerated a bomb. Current bombs: " + bombCount);
185195
}
186196
}
187-
197+
188198
/**
189199
* Regenerates the specified number of bombs, not exceeding the maximum.
190-
*
200+
*
191201
* @param count The number of bombs to regenerate
192202
*/
193203
private void regenerateBomb(int count) {
194204
bombCount = Math.min(bombCount + count, maxBombCount);
195205
updateBombUI();
196206
}
207+
208+
public int getCoinCounter() {
209+
return coinCounter;
210+
}
197211
}

src/main/java/com/dinosaur/dinosaurexploder/components/CollectedCoinsComponent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void onAdded() {
4040
entity.getViewComponent().addChild(coinUI);
4141
}
4242

43-
private void updateText() {
43+
protected void updateText() {
4444
coinText.setText(languageManager.getTranslation("coin") + ": " + coin);
4545
}
4646

@@ -79,4 +79,8 @@ public void incrementCoin() {
7979
updateText();
8080
saveTotalCoins();
8181
}
82+
83+
public int getCoin() {
84+
return coin;
85+
}
8286
}

src/main/java/com/dinosaur/dinosaurexploder/components/GreenDinoComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void shoot() {
6767
Point2D center = entity.getCenter();
6868
Vec2 direction = Vec2.fromAngle(entity.getRotation() +90);
6969
spawn("basicEnemyProjectile",
70-
new SpawnData(center.getX() + 50 +3, center.getY())
70+
new SpawnData(center.getX(), center.getY())
7171
.put("direction", direction.toPoint2D() )
7272
);
7373
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,26 @@
2020
public class LifeComponent extends Component implements Life {
2121

2222
private static final int MAX_LIVES = 3;
23-
private final Image heart = new Image(GameConstants.HEART_IMAGE_PATH);
24-
private final Image heartLost = new Image(GameConstants.HEART_LOST_IMAGE_PATH);
23+
private Image heart;
24+
private Image heartLost;
2525
private int life = MAX_LIVES;
2626

2727
// Declaring Lives Text
2828
private Text lifeText;
2929
// Declaring 3 Hearts
30-
private final ImageView heart1 = new ImageView(heart);
31-
private final ImageView heart2 = new ImageView(heart);
32-
private final ImageView heart3 = new ImageView(heart);
30+
private ImageView heart1;
31+
private ImageView heart2;
32+
private ImageView heart3;
3333

3434
private final LanguageManager languageManager = LanguageManager.getInstance();
3535

3636
@Override
3737
public void onAdded() {
38+
heart = new Image(GameConstants.HEART_IMAGE_PATH);
39+
heart1 = new ImageView(heart);
40+
heart2 = new ImageView(heart);
41+
heart3 = new ImageView(heart);
42+
3843
// Initialize lifeText with the translated string
3944
lifeText = new Text(languageManager.getTranslation("lives"));
4045

@@ -59,6 +64,7 @@ private void updateTexts() {
5964
}
6065

6166
private void updateLifeDisplay() {
67+
heartLost = new Image(GameConstants.HEART_LOST_IMAGE_PATH);
6268
// Clear previous entities
6369
clearEntity();
6470

@@ -113,4 +119,8 @@ public int decreaseLife(int i) {
113119
life -= i;
114120
return life;
115121
}
122+
123+
public int getLife() {
124+
return life;
125+
}
116126
}

src/main/java/com/dinosaur/dinosaurexploder/components/RedDinoComponent.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.almasb.fxgl.dsl.FXGL;
55
import com.almasb.fxgl.entity.SpawnData;
66
import com.almasb.fxgl.entity.component.Component;
7-
import com.almasb.fxgl.time.LocalTimer;
87
import com.dinosaur.dinosaurexploder.interfaces.Dinosaur;
8+
import com.dinosaur.dinosaurexploder.utils.GameTimer;
99
import com.dinosaur.dinosaurexploder.utils.LevelManager;
1010
import com.dinosaur.dinosaurexploder.view.DinosaurGUI;
1111
import com.dinosaur.dinosaurexploder.constants.GameConstants;
@@ -16,12 +16,17 @@
1616

1717
/**
1818
* Summary :
19-
* This class extends Component and Implements the Dinosaur Classes and Handles the Shooting and Updating the Dino
19+
* This class extends Component and Implements the Dinosaur Classes and Handles the Shooting and Updating the Dino
2020
*/
2121
public class RedDinoComponent extends Component implements Dinosaur {
2222
double horizontalSpeed = 1.5;
23-
public int lives = 10;
24-
private LocalTimer shootTimer = FXGL.newLocalTimer();
23+
private int lives = 10;
24+
private final GameTimer gameTimer;
25+
26+
public RedDinoComponent(GameTimer gameTimer) {
27+
this.gameTimer = gameTimer;
28+
}
29+
2530
private boolean isPaused = false;
2631
private boolean isMuted = false;
2732

@@ -58,57 +63,57 @@ public void setMuted(boolean muted) {
5863
}
5964

6065
@Override
61-
public void onAdded(){
66+
public void onAdded() {
6267
//Get the current enemy speed from the level manager
6368
//levelManager = FXGL.geto("levelManager");
6469
firstTime = true;
6570
}
71+
6672
/**
6773
* Summary :
68-
* This method runs for every frame like a continues flow , without any stop until we put stop to it.
74+
* This method runs for every frame like a continues flow , without any stop until we put stop to it.
6975
* Parameters :
70-
* double ptf
76+
* double ptf
7177
*/
7278
@Override
7379
public void onUpdate(double ptf) {
74-
if(isPaused) return;
80+
if (isPaused) return;
7581

76-
if(firstTime){
82+
if (firstTime) {
7783
System.out.println("level: " + levelManager.getCurrentLevel());
7884
horizontalSpeed = levelManager.getEnemySpeed();
79-
lives = levelManager.getCurrentLevel()*2;
85+
lives = levelManager.getCurrentLevel() * 2;
8086
firstTime = false;
8187
}
8288

8389
// the Dino turns around just before he hits a site of the screen
84-
if(entity.getX() < 0 || entity.getX() > DinosaurGUI.WIDTH - entity.getWidth()-40) {
90+
if (entity.getX() < 0 || entity.getX() > DinosaurGUI.WIDTH - entity.getWidth() - 40) {
8591
horizontalSpeed *= -1;
8692
}
8793
entity.translateX(horizontalSpeed);
8894

8995
//The dinosaur shoots depending on the absolute value of its own speed on the current Level
9096

91-
if (shootTimer.elapsed(Duration.seconds(levelManager.getEnemySpawnRate()*1.3)))
92-
{
97+
if (gameTimer.isElapsed(Duration.seconds(levelManager.getEnemySpawnRate() * 1.3))) {
9398
shoot();
94-
shootTimer.capture();
99+
gameTimer.capture();
95100
}
96101
}
97102

98103
/**
99104
* Summary :
100-
* This handles with the shooting of the dinosaur and spawning of the new bullet
105+
* This handles with the shooting of the dinosaur and spawning of the new bullet
101106
*/
102107
@Override
103108
public void shoot() {
104-
if(!isMuted) {
109+
if (!isMuted) {
105110
FXGL.play(GameConstants.ENEMY_SHOOT_SOUND);
106111
}
107112
Point2D center = entity.getCenter();
108-
Vec2 direction = Vec2.fromAngle(entity.getRotation() + 90 + random(-45,45));
113+
Vec2 direction = Vec2.fromAngle(entity.getRotation() + 90 + random(-45, 45));
109114
spawn("basicEnemyProjectile",
110-
new SpawnData(center.getX() + 50 +3, center.getY())
111-
.put("direction", direction.toPoint2D() )
115+
new SpawnData(center.getX() + 50 + 3, center.getY())
116+
.put("direction", direction.toPoint2D())
112117
);
113118
}
114119

0 commit comments

Comments
 (0)