From bc0c2723e96b6b0769520eb33bc932fce688d62d Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 15 Mar 2016 14:34:33 +0100 Subject: Implement the applyTo method for INC_BOMB and INC_RANGE --- src/ch/epfl/xblast/server/Bonus.java | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/ch/epfl/xblast/server/Bonus.java b/src/ch/epfl/xblast/server/Bonus.java index 09a2248..f22c9fe 100644 --- a/src/ch/epfl/xblast/server/Bonus.java +++ b/src/ch/epfl/xblast/server/Bonus.java @@ -1,40 +1,53 @@ package ch.epfl.xblast.server; /** - * Bonuses. - * - * @author Pacien TRAN-GIRARD (261948) - * @author Timothée FLOURE (257420) + * @author TimothéE FLOURE (257420) */ public enum Bonus { /** - * Increases the maximum number of bombs used simultaneously. + * Increase the maximum number of bombs used simultaneously. */ INC_BOMB { @Override public Player applyTo(Player player) { - // TODO - return null; + if (player.maxBombs() < BOMBS_LIMIT) { + return player.withMaxBombs(player.maxBombs() + 1); + } else { + return player.withMaxBombs(BOMBS_LIMIT); + } } }, /** - * Increases the range of the bombs. + * Increase the range of the bombs. */ INC_RANGE { @Override public Player applyTo(Player player) { - // TODO - return null; + if (player.bombRange() < RANGE_LIMIT) { + return player.withBombRange(player.bombRange() + 1); + } else { + return player.withBombRange(RANGE_LIMIT); + } } }; + /** + * Maximum number of bombs. + */ + private final int BOMBS_LIMIT = 9; + + /** + * Maximum range of a bomb. + */ + private final int RANGE_LIMIT = 9; + /** * Apply the bonus to the given player. * * @param player receiving the bonus + * @return a new player with the modified values */ abstract public Player applyTo(Player player); - } -- cgit v1.2.3