Search in sources :

Example 1 with Unit

use of coderoyale2.units.Unit in project warlords-duel by Warlord56x.

the class Buy method doCommand.

@Override
protected void doCommand(ArrayList<Object> args) throws CommandException {
    String msg = "noerror";
    CommandException temp = new CommandException(msg);
    boolean ok = true;
    int amount = (int) args.get(2);
    String stat = (String) args.get(1);
    try {
        int price = getCurrentHero().incStat(stat, amount);
        getCurrentHero().setStat("gold", getCurrentHero().getStat("gold") - price);
        println("Current gold: " + getCurrentHero().getStat("gold"));
    } catch (HeroException e) {
        temp = new CommandException(e.getMessage());
        msg = e.getMessage();
    } finally {
        if (msg == "noerror") {
            println(msg);
            return;
        }
        String unitID = (String) args.get(1);
        if (!unitIDs.contains(unitID)) {
            ok = false;
            temp = new CommandException("No unit or stat called: " + unitID + " exists!");
        }
        if (!ok) {
            throw temp;
        }
        for (Unit unit : getCurrentUnitList()) {
            if (unit.getId().equals(unitID)) {
                try {
                    getCurrentUnitList().add(getCurrentHero().buyUnits(unitID, unit.getSize() + amount));
                    getCurrentUnitList().remove(unit);
                    println("Current gold: " + getCurrentHero().getStat("gold"));
                } catch (HeroException e) {
                    throw new CommandException(e.getMessage());
                }
            }
        }
        try {
            getCurrentUnitList().add(getCurrentHero().buyUnits(unitID, amount));
        } catch (HeroException e) {
            throw new CommandException(e.getMessage());
        }
        println("Current gold: " + getCurrentHero().getStat("gold"));
    }
}
Also used : HeroException(GameExceptions.HeroException) CommandException(GameExceptions.CommandException) Unit(Units.Unit)

Example 2 with Unit

use of coderoyale2.units.Unit in project warlords-duel by Warlord56x.

the class Units method doCommand.

@Override
protected void doCommand(ArrayList<Object> args) throws CommandException {
    String str = "\n";
    for (Unit unit : units) {
        str += unit.getName() + "\n";
    }
    println(str);
}
Also used : Unit(Units.Unit)

Example 3 with Unit

use of coderoyale2.units.Unit in project warlords-duel by Warlord56x.

the class EnemyUnits method doCommand.

@Override
protected void doCommand(ArrayList<Object> args) throws CommandException {
    String str = "";
    Boolean e = false;
    if (getEnemyHeroUnitList() != null) {
        if (getEnemyHeroUnitList().isEmpty()) {
            e = true;
        }
    } else {
        e = true;
    }
    if (e) {
        throw new CommandException("Hero doesn't have any units!");
    }
    for (Unit unit : getEnemyHeroUnitList()) {
        str += "Name: " + unit.getName() + " size: " + unit.getSize() + "\n";
    }
    println(str);
}
Also used : CommandException(GameExceptions.CommandException) Unit(Units.Unit)

Example 4 with Unit

use of coderoyale2.units.Unit in project sample by keepinmindsh.

the class SaveFiles method createUnitForSave.

private List<Unit> createUnitForSave(List<Unit> unitList) {
    List<Unit> returnUnitList = new ArrayList<>();
    unitList.forEach(unit -> {
        Marine.Builder maringBuilder = new Marine.Builder(40).setAttackGuage(6).setMarineName("마린 1");
        maringBuilder.setUnitState(unit.getUnitStatus());
        Marine marine = maringBuilder.build();
        returnUnitList.add(marine);
    });
    return returnUnitList;
}
Also used : Marine(designpattern.gof_memento.sample03.units.Marine) ArrayList(java.util.ArrayList) Unit(designpattern.gof_memento.sample03.units.Unit)

Example 5 with Unit

use of coderoyale2.units.Unit in project sample by keepinmindsh.

the class SampleFiles method main.

public static void main(String[] args) throws Exception {
    Unit marine1 = new Marine.Builder(40).setAttackGuage(6).setMarineName("마린 1").setShield(0).build();
    Unit zealot1 = new Zealot.Builder(100).setAttackGuage(16).setZealotName("질럿 1").setShield(60).build();
    SaveFiles saveFiles = new SaveFiles();
    saveFiles.setSavePoint(Arrays.asList(marine1));
    marine1.damaged(zealot1.attack());
    Arrays.asList(marine1).stream().forEach(unit -> {
        unit.checkHealthStatus();
    });
    saveFiles.setSavePoint(Arrays.asList(marine1));
    List<Unit> list = saveFiles.getUnitFromSavePoint(0);
    for (Unit unit : list) {
        if (unit instanceof Marine) {
            marine1 = unit;
        }
    }
    Arrays.asList(marine1).stream().forEach(unit -> {
        unit.checkHealthStatus();
    });
    List<Unit> list2 = saveFiles.getUnitFromSavePoint(1);
    for (Unit unit : list2) {
        if (unit instanceof Marine) {
            marine1 = unit;
        }
    }
    Arrays.asList(marine1).stream().forEach(unit -> {
        unit.checkHealthStatus();
    });
}
Also used : Marine(designpattern.gof_memento.sample03.units.Marine) Unit(designpattern.gof_memento.sample03.units.Unit) SaveFiles(designpattern.gof_memento.sample03.gamesave.SaveFiles)

Aggregations

Unit (Units.Unit)88 GameAction (Engine.GameAction)28 XYCoord (Engine.XYCoord)28 MapLocation (Terrain.MapLocation)13 ArrayList (java.util.ArrayList)13 BattleLifecycle (Engine.UnitActionLifecycles.BattleLifecycle)10 GamePath (Engine.GamePath)9 Commander (CommandingOfficers.Commander)8 GameEventQueue (Engine.GameEvents.GameEventQueue)7 CommandException (GameExceptions.CommandException)7 GameEvent (Engine.GameEvents.GameEvent)6 LoadLifecycle (Engine.UnitActionLifecycles.LoadLifecycle)5 BattleSummary (Engine.Combat.BattleSummary)4 GameActionSet (Engine.GameActionSet)4 TerrainType (Terrain.TerrainType)4 UnitModel (Units.UnitModel)4 HashSet (java.util.HashSet)4 CommanderAbility (CommandingOfficers.CommanderAbility)3 ArmyDefeatEvent (Engine.GameEvents.ArmyDefeatEvent)3 CaptureLifecycle (Engine.UnitActionLifecycles.CaptureLifecycle)3