diff options
Diffstat (limited to 'src/main')
4 files changed, 64 insertions, 4 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java b/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java index e8e5d163..8f50db29 100644 --- a/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java +++ b/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java @@ -2,6 +2,11 @@ package org.luxons.sevenwonders.game.data.serializers; import java.lang.reflect.Type; +import org.luxons.sevenwonders.game.effects.Effect; +import org.luxons.sevenwonders.game.effects.GoldIncrease; +import org.luxons.sevenwonders.game.effects.MilitaryReinforcements; +import org.luxons.sevenwonders.game.effects.RawPointsIncrease; + import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -9,10 +14,6 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import org.luxons.sevenwonders.game.effects.Effect; -import org.luxons.sevenwonders.game.effects.GoldIncrease; -import org.luxons.sevenwonders.game.effects.MilitaryReinforcements; -import org.luxons.sevenwonders.game.effects.RawPointsIncrease; public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDeserializer<Effect> { @@ -25,6 +26,8 @@ public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDese value = ((GoldIncrease)effect).getAmount(); } else if (RawPointsIncrease.class.equals(typeOfSrc)) { value = ((RawPointsIncrease)effect).getPoints(); + } else { + throw new IllegalArgumentException("Unknown numeric effet " + typeOfSrc.getTypeName()); } return new JsonPrimitive(value); } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java index c2250d23..8a319ab6 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java @@ -1,5 +1,7 @@ package org.luxons.sevenwonders.game.effects; +import java.util.Objects; + import org.luxons.sevenwonders.game.boards.Board; public class GoldIncrease extends InstantEffect { @@ -18,4 +20,21 @@ public class GoldIncrease extends InstantEffect { public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { board.setGold(board.getGold() + amount); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GoldIncrease that = (GoldIncrease)o; + return amount == that.amount; + } + + @Override + public int hashCode() { + return Objects.hash(amount); + } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java index 7cfa4905..ad1497dd 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java @@ -1,5 +1,7 @@ package org.luxons.sevenwonders.game.effects; +import java.util.Objects; + import org.luxons.sevenwonders.game.boards.Board; public class MilitaryReinforcements extends InstantEffect { @@ -18,4 +20,21 @@ public class MilitaryReinforcements extends InstantEffect { public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { board.setNbWarSymbols(board.getNbWarSymbols() + count); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MilitaryReinforcements that = (MilitaryReinforcements)o; + return count == that.count; + } + + @Override + public int hashCode() { + return Objects.hash(count); + } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java index 53fcecd4..76ab30b0 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java @@ -1,5 +1,7 @@ package org.luxons.sevenwonders.game.effects; +import java.util.Objects; + import org.luxons.sevenwonders.game.boards.Board; public class RawPointsIncrease extends EndGameEffect { @@ -18,4 +20,21 @@ public class RawPointsIncrease extends EndGameEffect { public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { return points; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RawPointsIncrease that = (RawPointsIncrease)o; + return points == that.points; + } + + @Override + public int hashCode() { + return Objects.hash(points); + } } |