diff --git a/app/src/main/java/ch/logixisland/anuto/business/game/GameSpeed.java b/app/src/main/java/ch/logixisland/anuto/business/game/GameSpeed.java index 7689eda5..191fdc6b 100755 --- a/app/src/main/java/ch/logixisland/anuto/business/game/GameSpeed.java +++ b/app/src/main/java/ch/logixisland/anuto/business/game/GameSpeed.java @@ -8,7 +8,7 @@ public class GameSpeed { - private static final int FAST_FORWARD_SPEED = 4; + private static final int SPEED_LEVELS[] = {1, 4, 8}; public interface Listener { void gameSpeedChanged(); @@ -17,14 +17,14 @@ public interface Listener { private final GameEngine mGameEngine; private final List mListeners = new CopyOnWriteArrayList<>(); - private boolean mFastForwardActive = false; + private int mCurrentSpeed = SPEED_LEVELS[0]; public GameSpeed(GameEngine gameEngine) { mGameEngine = gameEngine; } - public boolean isFastForwardActive() { - return mFastForwardActive; + public int getCurrentSpeed() { + return mCurrentSpeed; } public void toggleFastForward() { @@ -38,7 +38,15 @@ public void execute() { return; } - setFastForwardActive(!mFastForwardActive); + int index = 0; + for (int level : SPEED_LEVELS) { + if (level == mCurrentSpeed) { + index++; + break; + } + index++; + } + setFastForwardActive(SPEED_LEVELS[index % SPEED_LEVELS.length]); } public void addListener(Listener listener) { @@ -49,10 +57,10 @@ public void removeListener(Listener listener) { mListeners.remove(listener); } - private void setFastForwardActive(boolean fastForwardActive) { - if (mFastForwardActive != fastForwardActive) { - mFastForwardActive = fastForwardActive; - mGameEngine.setTicksPerLoop(mFastForwardActive ? FAST_FORWARD_SPEED : 1); + private void setFastForwardActive(int currentSpeed) { + if (mCurrentSpeed != currentSpeed) { + mCurrentSpeed = currentSpeed; + mGameEngine.setTicksPerLoop(mCurrentSpeed); for (Listener listener : mListeners) { listener.gameSpeedChanged(); diff --git a/app/src/main/java/ch/logixisland/anuto/view/game/HeaderFragment.java b/app/src/main/java/ch/logixisland/anuto/view/game/HeaderFragment.java index d5cbbfa0..459eea97 100755 --- a/app/src/main/java/ch/logixisland/anuto/view/game/HeaderFragment.java +++ b/app/src/main/java/ch/logixisland/anuto/view/game/HeaderFragment.java @@ -84,7 +84,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, txt_credits.setText(getString(R.string.credits) + ": " + StringUtils.formatSuffix(mScoreBoard.getCredits())); txt_lives.setText(getString(R.string.lives) + ": " + mScoreBoard.getLives()); txt_bonus.setText(getString(R.string.bonus) + ": " + StringUtils.formatSuffix(mScoreBoard.getWaveBonus() + mScoreBoard.getEarlyBonus())); - btn_fast_forward.setText(getString(mSpeedManager.isFastForwardActive() ? R.string.fast_speed : R.string.normal_speed)); + btn_fast_forward.setText(mSpeedManager.getCurrentSpeed() + "x"); final List towerViews = new ArrayList<>(); towerViews.add((TowerView) v.findViewById(R.id.view_tower_1)); @@ -226,7 +226,7 @@ public void gameSpeedChanged() { mHandler.post(new Runnable() { @Override public void run() { - btn_fast_forward.setText(getString(mSpeedManager.isFastForwardActive() ? R.string.fast_speed : R.string.normal_speed)); + btn_fast_forward.setText(mSpeedManager.getCurrentSpeed() + "x"); } }); }