Android Open Source - ubisoldiers Battle Log Entry






From Project

Back to project page ubisoldiers.

License

The source code is released under:

MIT License

If you think the Android project ubisoldiers 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.github.gobbisanches.ubisoldiers.mechanics;
//from  w  w  w  . j  a  v  a  2 s.com
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sanches on 7/4/14.
 */
public class BattleLogEntry implements Serializable {
    public enum ShootingDirection { FROM_ATTACKER, FROM_DEFENDER };
    private static final long serialVersionUID = 1L;
    private Type type;
    private List<String> params;

    private BattleLogEntry(Type type, List<String> params) {
        this.type = type;
        this.params = params;
    }

    public static BattleLogEntry createShootingEntry(int round, ShootingDirection direction,
                                                     BattleUnit shooter,
                                                     BattleUnit target,
                                                     int damage) {
        List<String> params = new ArrayList<String>();

        params.add(Integer.toString(round));
        params.add(direction.name());
        params.add(shooter.getSoldierName());
        params.add(target.getSoldierName());
        params.add(Integer.toString(damage));

        return new BattleLogEntry(BattleLogEntry.Type.SHOOTING, params);
    }

    public static BattleLogEntry createBattleResultEntry(
            BattleResultType battleResultType) {
        List<String> params = new ArrayList<String>();
        params.add(battleResultType.name());

        return new BattleLogEntry(Type.BATTLE_RESULT, params);
    }

    public void getParsedBy(BattleLogParser parser) {
        switch (type) {
            case SHOOTING:
                shootingGetParsedBy(parser);
                break;
            case BATTLE_RESULT:
                battleResultGetParsedBy(parser);
                break;
            default:
                throw new RuntimeException("Invalid Log Entry Type " + type);
        }
    }

    private void battleResultGetParsedBy(BattleLogParser parser) {
        BattleResultType result = BattleResultType.valueOf(params.get(0));
        parser.parseBattleResultEntry(result);
    }

    private void shootingGetParsedBy(BattleLogParser parser) {
        int round = Integer.valueOf(params.get(0)).intValue();
        ShootingDirection direction = ShootingDirection.valueOf(params.get(1));
        String shooterName = params.get(2);
        String targetName = params.get(3);
        int damage = Integer.valueOf(params.get(4)).intValue();

        parser.parseShootingEntry(round, direction, shooterName, targetName, damage);
    }

    public enum Type {SHOOTING, BATTLE_RESULT}

    public enum BattleResultType {ATTACKER_WON, DEFENDER_WON, DRAW}

    @Override
    public String toString() {
        return "BattleLogEntry{" +
                "type=" + type +
                ", params=" + params +
                "}\n";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BattleLogEntry)) return false;

        BattleLogEntry that = (BattleLogEntry) o;

        if (!params.equals(that.params)) return false;
        if (type != that.type) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = type.hashCode();
        result = 31 * result + params.hashCode();
        return result;
    }
}




Java Source Code List

com.github.gobbisanches.ubisoldiers.app.ArmyFragment.java
com.github.gobbisanches.ubisoldiers.app.BattleActivity.java
com.github.gobbisanches.ubisoldiers.app.BattleFragment.java
com.github.gobbisanches.ubisoldiers.app.ItemListFragment.java
com.github.gobbisanches.ubisoldiers.app.MainActivity.java
com.github.gobbisanches.ubisoldiers.app.ResourceManager.java
com.github.gobbisanches.ubisoldiers.app.SingleFragmentActivity.java
com.github.gobbisanches.ubisoldiers.app.UbisoldierUosApplication.java
com.github.gobbisanches.ubisoldiers.app.UbisoldiersDriver.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationActivity.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationFragment.java
com.github.gobbisanches.ubisoldiers.app.UnitFragment.java
com.github.gobbisanches.ubisoldiers.app.UosManager.java
com.github.gobbisanches.ubisoldiers.mechanics.Armor.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogEntry.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogParser.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLog.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleSquad.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleUnit.java
com.github.gobbisanches.ubisoldiers.mechanics.Battle.java
com.github.gobbisanches.ubisoldiers.mechanics.DefaultGameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.GameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.General.java
com.github.gobbisanches.ubisoldiers.mechanics.ItemCollection.java
com.github.gobbisanches.ubisoldiers.mechanics.Item.java
com.github.gobbisanches.ubisoldiers.mechanics.MechanicsEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.PolicyManager.java
com.github.gobbisanches.ubisoldiers.mechanics.SearchEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.Soldier.java
com.github.gobbisanches.ubisoldiers.mechanics.Squad.java
com.github.gobbisanches.ubisoldiers.mechanics.Unit.java
com.github.gobbisanches.ubisoldiers.mechanics.Weapon.java