Skip to content

Commit 98d861a

Browse files
committed
Merge branch 'main' of github.com:GioeleBucci/TBOOOP into nico-dev
2 parents d80f5c5 + 66c156f commit 98d861a

File tree

8 files changed

+125
-41
lines changed

8 files changed

+125
-41
lines changed

src/main/java/tbooop/commons/impl/Point2dImpl.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ public double distance(final Point2d coord) {
7575
/** {@inheritDoc} */
7676
@Override
7777
public boolean equals(final Object obj) {
78-
if (obj instanceof Point2d) {
79-
return this.vector.equals(toV2D((Point2d) obj));
80-
}
81-
return false;
78+
return obj instanceof Point2d && this.vector.equals(toV2D((Point2d) obj));
8279
}
8380

8481
/** {@inheritDoc} */

src/main/java/tbooop/commons/impl/Vector2dImpl.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,25 @@ public double getLenght() {
5757
/** {@inheritDoc} */
5858
@Override
5959
public Vector2d normalize() {
60-
return toVector(this.vector.normalize());
60+
return toV2d(this.vector.normalize());
6161
}
6262

6363
/** {@inheritDoc} */
6464
@Override
6565
public Vector2d negate() {
66-
return toVector(this.vector.negate());
66+
return toV2d(this.vector.negate());
6767
}
6868

6969
/** {@inheritDoc} */
7070
@Override
7171
public Vector2d scalarMultiply(final double a) {
72-
return toVector(this.vector.scalarMultiply(a));
72+
return toV2d(this.vector.scalarMultiply(a));
7373
}
7474

7575
/** {@inheritDoc} */
7676
@Override
7777
public boolean equals(final Object obj) {
78-
if (obj instanceof Vector2d) {
79-
return this.vector.equals(toV2D((Vector2d) obj));
80-
}
81-
return false;
78+
return obj instanceof Vector2d && this.vector.equals(toV2D((Vector2d) obj));
8279
}
8380

8481
/** {@inheritDoc} */
@@ -99,7 +96,7 @@ public Point2d toP2d() {
9996
return new Point2dImpl(getX(), getY());
10097
}
10198

102-
private Vector2d toVector(final Vector2D v) {
99+
private Vector2d toV2d(final Vector2D v) {
103100
return new Vector2dImpl(v.getX(), v.getY());
104101
}
105102

src/main/java/tbooop/model/player/api/Player.java

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package tbooop.model.player.api;
22

33
import tbooop.model.core.api.movable.Entity;
4-
import tbooop.model.player.api.coin.PlayerCoin;
5-
import tbooop.model.player.api.key.PlayerKey;
64
import tbooop.commons.api.CardinalDirection;
75
import tbooop.commons.api.Vector2d;
86

@@ -11,7 +9,7 @@
119
* a player can interact with an enemy trying to kill him or can collect
1210
* objects on the map.
1311
*/
14-
public interface Player extends Entity, UnmodifiablePlayer, PlayerKey, PlayerCoin {
12+
public interface Player extends Entity, UnmodifiablePlayer {
1513

1614
/**
1715
* Set the current health equals to the max health.
@@ -59,4 +57,35 @@ public interface Player extends Entity, UnmodifiablePlayer, PlayerKey, PlayerCoi
5957
* @param amount the amount to increase;
6058
*/
6159
void increaseMaxHealth(int amount);
60+
61+
/**
62+
* Adds the specified number of coins to the collection.
63+
*
64+
* @param coins the number of coins to add
65+
*/
66+
void addCoins(int coins);
67+
68+
/**
69+
* Consumes the specified number of coins from the collection.
70+
*
71+
* @param coins the number of coins to consume
72+
*/
73+
void consumeCoins(int coins);
74+
75+
/**
76+
* Indicates whether the collection has a key.
77+
*
78+
* @return true if the collection has a key, otherwise false
79+
*/
80+
boolean hasKey();
81+
82+
/**
83+
* Decrement the number of key to the collection by 1.
84+
*/
85+
void useKey();
86+
87+
/**
88+
* Increment the number of key to the collection by 1.
89+
*/
90+
void pickupKey();
6291
}

src/main/java/tbooop/view/api/Keybinds.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static boolean isMove(final Keybinds keybind) {
129129
*/
130130
public static Optional<Keybinds> getKeybind(final KeyCode keyCode) {
131131
for (final Keybinds keybind : Keybinds.values()) {
132-
if (keybind.getKeyCode() == keyCode) {
132+
if (keybind.getKeyCode().equals(keyCode)) {
133133
return Optional.of(keybind);
134134
}
135135
}

src/main/java/tbooop/view/player/HealthRender.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ public void addMaxHealth(final ImageView heartView, final HBox root) {
4545
private void bindHeart(final ImageView heartView, final HBox root) {
4646
root.getChildren().add(heartView);
4747

48-
heartView.fitWidthProperty()
49-
.bind(root.getScene()
50-
.widthProperty()
51-
.multiply(heartView.getImage().getWidth() / root.getScene().widthProperty().get()));
52-
53-
heartView.fitHeightProperty()
54-
.bind(root.getScene()
55-
.heightProperty()
56-
.multiply(heartView.getImage().getHeight() / root.getScene().heightProperty().get()));
57-
58-
heartView.setScaleX(HEART_SIZE);
59-
heartView.setScaleY(HEART_SIZE);
48+
heartView.fitWidthProperty()
49+
.bind(root.getScene()
50+
.widthProperty()
51+
.multiply(heartView.getImage().getWidth() / root.getScene().widthProperty().get()));
52+
53+
heartView.fitHeightProperty()
54+
.bind(root.getScene()
55+
.heightProperty()
56+
.multiply(heartView.getImage().getHeight() / root.getScene().heightProperty().get()));
57+
58+
heartView.setScaleX(HEART_SIZE);
59+
heartView.setScaleY(HEART_SIZE);
6060
}
6161
}

src/test/java/tbooop/AppTest.java

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tbooop.model.player;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tbooop.model.player.impl.BasePlayerCoinImpl;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.junit.jupiter.api.BeforeAll;
10+
11+
class BasePlayerCoinImplTest {
12+
13+
private static final int TEST_COIN = 50;
14+
private static final int MAX_COIN = 200;
15+
private static BasePlayerCoinImpl playerCoin;
16+
17+
@BeforeAll
18+
static void setUp() {
19+
playerCoin = new BasePlayerCoinImpl();
20+
}
21+
22+
@Test
23+
void addCoins() {
24+
final int initialCoinCount = playerCoin.getCoins();
25+
final int coinsToAdd = TEST_COIN;
26+
playerCoin.addCoins(coinsToAdd);
27+
assertEquals(initialCoinCount + coinsToAdd, playerCoin.getCoins());
28+
}
29+
30+
@Test
31+
void addOverMax() {
32+
final int initialCoinCount = playerCoin.getCoins();
33+
final int coinsToAdd = MAX_COIN + TEST_COIN;
34+
playerCoin.addCoins(coinsToAdd);
35+
assertEquals(initialCoinCount, playerCoin.getCoins());
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tbooop.model.player;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tbooop.model.player.impl.BasePlayerKeyImpl;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.junit.jupiter.api.BeforeAll;
10+
11+
class BasePlayerKeyImplTest {
12+
13+
private static final int MAX_KEYS = 20;
14+
private static BasePlayerKeyImpl playerKey;
15+
16+
@BeforeAll
17+
static void setUp() {
18+
playerKey = new BasePlayerKeyImpl();
19+
}
20+
21+
@Test
22+
void pickupKey() {
23+
final int initialKeyCount = playerKey.getKey();
24+
playerKey.pickupKey();
25+
assertEquals(initialKeyCount + 1, playerKey.getKey());
26+
}
27+
28+
@Test
29+
void pickupToMax() {
30+
final int initialKeyCount = playerKey.getKey();
31+
for (int i = initialKeyCount; i < MAX_KEYS; i++) {
32+
playerKey.pickupKey();
33+
}
34+
playerKey.pickupKey();
35+
assertEquals(MAX_KEYS, playerKey.getKey());
36+
}
37+
}

0 commit comments

Comments
 (0)