Nr.7: edited the 'Battlestate' and 'ShipMap' class

This commit is contained in:
Benjamin Feyer
2024-10-02 01:19:19 +02:00
parent 71a4ac8d12
commit 237bf15992
6 changed files with 14 additions and 5 deletions

View File

@@ -84,6 +84,7 @@ public void receivedEvent(ItemRemovedEvent event) {
@Override
public void receivedEvent(ItemAddedEvent event) {
if (shipMap == event.map())
add(event.item());
}
}

View File

@@ -50,17 +50,20 @@ else if (logic.getOpponentMap().isValid(pos))
*
* @param msg the message containing the effect of the shot
*/
//tODO
@Override
public void receivedEffect(EffectMessage msg) {
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
playSound(msg);
myTurn = msg.isMyTurn();
logic.setInfoText(msg.getInfoTextKey());
myTurn = msg.isMyTurn(); //boolean, describes whether it is my turn
logic.setInfoText(msg.getInfoTextKey()); //
affectedMap(msg).add(msg.getShot());
if (destroyedOpponentShip(msg))
if (destroyedOpponentShip(msg)) {
logic.getOpponentMap().add(msg.getDestroyedShip());
}
if (msg.isGameOver()) {
msg.getRemainingOpponentShips().forEach(logic.getOwnMap()::add);
//msg.getRemainingOpponentShips().forEach(logic.getOwnMap()::add);
msg.getRemainingOpponentShips().forEach(logic.getOpponentMap()::add);
logic.setState(new GameOverState(logic));
}
}

View File

@@ -10,6 +10,7 @@
import pp.battleship.notification.GameEvent;
import pp.battleship.notification.GameEventBroker;
import pp.battleship.notification.ItemAddedEvent;
import pp.battleship.notification.ItemRemovedEvent;
import java.util.ArrayList;
import java.util.Collections;
@@ -97,7 +98,7 @@ public void add(Shot shot) {
*/
public void remove(Item item) {
items.remove(item);
notifyListeners(new ItemAddedEvent(item, this));
notifyListeners(new ItemRemovedEvent(item, this));
}
/**

View File

@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
import static pp.battleship.model.Battleship.Status.NORMAL;

View File

@@ -60,6 +60,7 @@ public void testRemoveItem() {
map.remove(battleship);
final List<Item> items = map.getItems();
assertFalse(items.contains(battleship));
//TODO
verify(mockBroker).notifyListeners(any(ItemAddedEvent.class));
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
}
@@ -74,6 +75,7 @@ public void testClear() {
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
}
@Test
public void testGetRemainingShips() {
map.add(battleship);