Android Open Source - shapemergency Bonus Factory






From Project

Back to project page shapemergency.

License

The source code is released under:

GNU General Public License

If you think the Android project shapemergency listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.adsg0186.shapemergency.testgame1;
/*from   ww  w .  j  av  a  2 s . c o m*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;

import android.util.Log;

import com.adsg0186.shapemergency.testgame1.GameSound.SoundId;
import com.adsg0186.shapemergency.testgame1.blobs.EnemyFactory;
import com.github.adsgray.gdxtry1.engine.WorldIF;
import com.github.adsgray.gdxtry1.engine.output.Renderer;
import com.github.adsgray.gdxtry1.engine.util.GameCommand;

/*
 */
public class BonusFactory {

    protected GameCommand incShield;
    protected GameCommand incHitPoints;
    protected GameCommand incScore;
    // required for creating FlashMessages
    protected WorldIF world;
    protected Renderer renderer;
    

    public BonusFactory(FiringGameTest game, WorldIF world, Renderer renderer) {
        this.world = world;
        this.renderer = renderer;

        incShield = game.new IncShield();
        incHitPoints = game.new IncHitPoints();
        incScore = game.new IncScore();
    }
    
    public static interface BonusCommandIF {
        public void execute();
    }

    public static class BonusCommand implements BonusCommandIF {
        protected GameCommand cmd;
        protected int num;

        public BonusCommand(GameCommand cmd, int num) {
            this.cmd = cmd;
            this.num = num;
        }

        @Override
        public void execute() {
            cmd.execute(num);
        }
        
    }
    
    protected void postBonusExecute(String msg) {
        EnemyFactory.flashMessage(world, renderer, msg, 70);
        GameSound.get().playSoundId(SoundId.bonusReceive);
    }

    public BonusCommandIF shieldBonus(int num) {
        GameCommand bonus = new GameCommand() {
            @Override public void execute(int num) {
                incShield.execute(num);
                postBonusExecute(String.format("%d Shield Bonus!", num));
            }
        };
        
        return new BonusCommand(bonus, num);
    } 
    
    public BonusCommandIF hitPointBonus(int num) {
        GameCommand bonus = new GameCommand() {
            @Override public void execute(int num) {
                incHitPoints.execute(num);
                postBonusExecute(String.format("%d Health Bonus!", num));
            }
        };
        
        return new BonusCommand(bonus, num);
    }
   
    public BonusCommandIF scoreBonus(int num) {
        GameCommand bonus = new GameCommand() {
            @Override public void execute(int num) {
                incScore.execute(num);
                postBonusExecute(String.format("%d Score Bonus!", num));
            }
        };
        
        return new BonusCommand(bonus, num);
    }
    
    // singleton
    protected static BonusFactory instance;
    public static BonusFactory createInstance(FiringGameTest game, WorldIF world, Renderer renderer) {
        // clobber instance. Anything that references world/renderer has to
        // be clobbered on creation.
        instance = null;
        if (instance == null) {
            instance = new BonusFactory(game, world, renderer);
        }
        return instance;
    }
    public static BonusFactory get() { return instance; }
}




Java Source Code List

com.adsg0186.shapemergency.GameActivity.java
com.adsg0186.shapemergency.GameScreen.java
com.adsg0186.shapemergency.HelpView.java
com.adsg0186.shapemergency.HighScoreView.java
com.adsg0186.shapemergency.MainActivity.java
com.adsg0186.shapemergency.SettingsView.java
com.adsg0186.shapemergency.testgame1.AngryTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.BonusFactory.java
com.adsg0186.shapemergency.testgame1.BossTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.CreateEnemyTrigger.java
com.adsg0186.shapemergency.testgame1.DefenderCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.FiringGameTest.java
com.adsg0186.shapemergency.testgame1.GameSound.java
com.adsg0186.shapemergency.testgame1.MissileBlobSource.java
com.adsg0186.shapemergency.testgame1.MissileCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.ShieldCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.TargetMissileSource.java
com.adsg0186.shapemergency.testgame1.TargetUtils.java
com.adsg0186.shapemergency.testgame1.Vibrate.java
com.adsg0186.shapemergency.testgame1.blobs.BonusDropper.java
com.adsg0186.shapemergency.testgame1.blobs.BonusIF.java
com.adsg0186.shapemergency.testgame1.blobs.BossEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.DamagableIF.java
com.adsg0186.shapemergency.testgame1.blobs.DamagerIF.java
com.adsg0186.shapemergency.testgame1.blobs.DefaultEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyBomb.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyFactory.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyIF.java
com.adsg0186.shapemergency.testgame1.blobs.FiringBlobDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.FlashMessage.java
com.adsg0186.shapemergency.testgame1.blobs.HitpointBonusDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.ScoreTextDisplay.java
com.adsg0186.shapemergency.testgame1.blobs.ShieldRing.java
com.adsg0186.shapemergency.testgame1.config.BaseGameConfig.java
com.adsg0186.shapemergency.testgame1.config.EasyGameConfig.java
com.adsg0186.shapemergency.testgame1.config.GameConfigIF.java
com.adsg0186.shapemergency.testgame1.config.GameConfig.java
com.adsg0186.shapemergency.testgame1.config.GamePreferences.java
com.adsg0186.shapemergency.testgame1.config.InsaneGameConfig.java
com.adsg0186.shapemergency.testgame1.config.SavedGame.java