Search in sources :

Example 1 with CascadeAnimation

use of com.janfic.games.computercombat.model.animations.CascadeAnimation in project computercombat by janfic.

the class MatchState method results.

public List<MoveResult> results(Move move) {
    List<MoveResult> results = new ArrayList<>();
    boolean extraTurn = false;
    while (isInvalidBoard() || getMatches().isEmpty() == false) {
        // Save Old State
        // Update
        update();
        // Collect Components
        Map<Integer, List<Component>> collected = collectComponents();
        Map<Component, Card> progress = new HashMap<>();
        CollectAnimation collectAnimation = new CollectAnimation(collected, progress);
        progress(collectAnimation);
        // Attack
        boolean attack = false;
        for (Integer integer : collected.keySet()) {
            for (Component component : collected.get(integer)) {
                if (component.getColor() == 5) {
                    attack = true;
                    break;
                }
            }
        }
        if (attack && activeEntities.get(currentPlayerMove).isEmpty() == false) {
            results.addAll(attack(move));
        }
        // Remove
        for (Integer matchNumber : collected.keySet()) {
            for (Component component : collected.get(matchNumber)) {
                this.componentBoard[component.getX()][component.getY()].changeColor(0);
            }
        }
        // Cascade
        // This can be optimized by storing collected components
        CascadeAnimation cascadeAnimation = new CascadeAnimation(cascade());
        List<MoveAnimation> moveAnimation = new ArrayList<>();
        moveAnimation.add(collectAnimation);
        moveAnimation.add(cascadeAnimation);
        for (Integer integer : collected.keySet()) {
            if (collected.get(integer).size() >= 4) {
                extraTurn = true;
            }
        }
        MoveResult result = new MoveResult(move, MatchState.record(this), moveAnimation);
        results.add(result);
    }
    if (extraTurn == false && results.size() > 0) {
        MoveResult last = results.get(results.size() - 1);
        last.getState().currentPlayerMove = last.getState().getOtherProfile(last.getState().currentPlayerMove);
        this.currentPlayerMove = last.getState().currentPlayerMove;
    }
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CollectAnimation(com.janfic.games.computercombat.model.animations.CollectAnimation) CascadeAnimation(com.janfic.games.computercombat.model.animations.CascadeAnimation) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Aggregations

Card (com.janfic.games.computercombat.model.Card)1 Component (com.janfic.games.computercombat.model.Component)1 CascadeAnimation (com.janfic.games.computercombat.model.animations.CascadeAnimation)1 CollectAnimation (com.janfic.games.computercombat.model.animations.CollectAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1