diff options
author | jbion <joffrey.bion@amadeus.com> | 2016-12-21 12:59:18 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2016-12-21 12:59:18 +0100 |
commit | b9c57b299c46a4fb9b2b8bf513f730257c45db4d (patch) | |
tree | 3fc999275e7ec02c0b0e30f2f02c38fa3984f698 /src/main | |
parent | Fix wonder name assignment for test constructor (diff) | |
download | seven-wonders-b9c57b299c46a4fb9b2b8bf513f730257c45db4d.tar.gz seven-wonders-b9c57b299c46a4fb9b2b8bf513f730257c45db4d.tar.bz2 seven-wonders-b9c57b299c46a4fb9b2b8bf513f730257c45db4d.zip |
Refactor switch into proper method override
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java | 26 | ||||
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java | 13 |
2 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java b/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java index f2bc2f38..34cab4a4 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java @@ -1,5 +1,29 @@ package org.luxons.sevenwonders.game.effects; +import java.util.List; + +import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.cards.Color; + public enum BoardElementType { - CARD, WONDER_LEVEL, DEFEAT_TOKEN + CARD { + @Override + int getElementCount(Board board, List<Color> colors) { + return board.getNbCardsOfColor(colors); + } + }, + WONDER_LEVEL { + @Override + int getElementCount(Board board, List<Color> colors) { + return board.getWonderLevel(); + } + }, + DEFEAT_TOKEN { + @Override + int getElementCount(Board board, List<Color> colors) { + return board.getNbDefeatTokens(); + } + }; + + abstract int getElementCount(Board board, List<Color> colors); } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java index 2796b63a..37db3532 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java @@ -84,17 +84,6 @@ public class BonusPerBoardElement implements Effect { } private int computeNbOfMatchingElementsIn(Board board) { - switch (type) { - case CARD: - return board.getNbCardsOfColor(colors); - case WONDER_LEVEL: - return board.getWonderLevel(); - case DEFEAT_TOKEN: - return board.getNbDefeatTokens(); - } - throw new UnsupportedBoardElementType(); - } - - private class UnsupportedBoardElementType extends RuntimeException { + return type.getElementCount(board, colors); } } |