Nr.7: edited the 'Battlestate' and 'ShipMap' class
This commit is contained in:
@@ -84,6 +84,7 @@ public void receivedEvent(ItemRemovedEvent event) {
|
|||||||
@Override
|
@Override
|
||||||
public void receivedEvent(ItemAddedEvent event) {
|
public void receivedEvent(ItemAddedEvent event) {
|
||||||
if (shipMap == event.map())
|
if (shipMap == event.map())
|
||||||
|
|
||||||
add(event.item());
|
add(event.item());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,17 +50,20 @@ else if (logic.getOpponentMap().isValid(pos))
|
|||||||
*
|
*
|
||||||
* @param msg the message containing the effect of the shot
|
* @param msg the message containing the effect of the shot
|
||||||
*/
|
*/
|
||||||
|
//tODO
|
||||||
@Override
|
@Override
|
||||||
public void receivedEffect(EffectMessage msg) {
|
public void receivedEffect(EffectMessage msg) {
|
||||||
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
|
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
|
||||||
playSound(msg);
|
playSound(msg);
|
||||||
myTurn = msg.isMyTurn();
|
myTurn = msg.isMyTurn(); //boolean, describes whether it is my turn
|
||||||
logic.setInfoText(msg.getInfoTextKey());
|
logic.setInfoText(msg.getInfoTextKey()); //
|
||||||
affectedMap(msg).add(msg.getShot());
|
affectedMap(msg).add(msg.getShot());
|
||||||
if (destroyedOpponentShip(msg))
|
if (destroyedOpponentShip(msg)) {
|
||||||
logic.getOpponentMap().add(msg.getDestroyedShip());
|
logic.getOpponentMap().add(msg.getDestroyedShip());
|
||||||
|
}
|
||||||
if (msg.isGameOver()) {
|
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));
|
logic.setState(new GameOverState(logic));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import pp.battleship.notification.GameEvent;
|
import pp.battleship.notification.GameEvent;
|
||||||
import pp.battleship.notification.GameEventBroker;
|
import pp.battleship.notification.GameEventBroker;
|
||||||
import pp.battleship.notification.ItemAddedEvent;
|
import pp.battleship.notification.ItemAddedEvent;
|
||||||
|
import pp.battleship.notification.ItemRemovedEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -97,7 +98,7 @@ public void add(Shot shot) {
|
|||||||
*/
|
*/
|
||||||
public void remove(Item item) {
|
public void remove(Item item) {
|
||||||
items.remove(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.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static pp.battleship.model.Battleship.Status.NORMAL;
|
import static pp.battleship.model.Battleship.Status.NORMAL;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public void testRemoveItem() {
|
|||||||
map.remove(battleship);
|
map.remove(battleship);
|
||||||
final List<Item> items = map.getItems();
|
final List<Item> items = map.getItems();
|
||||||
assertFalse(items.contains(battleship));
|
assertFalse(items.contains(battleship));
|
||||||
|
//TODO
|
||||||
verify(mockBroker).notifyListeners(any(ItemAddedEvent.class));
|
verify(mockBroker).notifyListeners(any(ItemAddedEvent.class));
|
||||||
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
|
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
|
||||||
}
|
}
|
||||||
@@ -74,6 +75,7 @@ public void testClear() {
|
|||||||
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
|
verify(mockBroker).notifyListeners(any(ItemRemovedEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRemainingShips() {
|
public void testGetRemainingShips() {
|
||||||
map.add(battleship);
|
map.add(battleship);
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ else if (o.y >= 0f)
|
|||||||
return det > 0f ? -1 : 1;
|
return det > 0f ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user