Nr.7: edited the 'Battlestate' and 'ShipMap' class
This commit is contained in:
@@ -84,6 +84,7 @@ public void receivedEvent(ItemRemovedEvent event) {
|
||||
@Override
|
||||
public void receivedEvent(ItemAddedEvent event) {
|
||||
if (shipMap == event.map())
|
||||
|
||||
add(event.item());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -232,6 +232,7 @@ else if (o.y >= 0f)
|
||||
return det > 0f ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
Reference in New Issue
Block a user