Search in sources :

Example 1 with SwitchAnimation

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

the class MatchComponentsMove method doMove.

@Override
public List<MoveResult> doMove(MatchState originalState) {
    List<MoveResult> results = new ArrayList<>();
    // Record Original State
    MoveResult r = new MoveResult(this, MatchState.record(originalState), new ArrayList<>());
    results.add(r);
    // Apply Switch
    Component[][] board = originalState.getComponentBoard();
    Component switchB = board[b.getX()][b.getY()];
    Component switchA = board[a.getX()][a.getY()];
    int bColor = switchB.getColor();
    switchB.changeColor(switchA.getColor());
    switchA.changeColor(bColor);
    // Switch and Create 1st MoveResult
    SwitchAnimation switchAnimation = new SwitchAnimation(a, b);
    List<MoveAnimation> animations = new ArrayList<>();
    animations.add(switchAnimation);
    // Record Switch
    MoveResult mr = new MoveResult(this, MatchState.record(originalState), animations);
    results.add(mr);
    switchA.invalidate();
    switchB.invalidate();
    switchA.invalidateNeighbors();
    switchB.invalidateNeighbors();
    List<MoveResult> collectLoop = originalState.results(this);
    // collectLoop = Move.collectComponentsCheck(originalState, this);
    results.addAll(collectLoop);
    GameRules.isGameOver(originalState);
    return results;
}
Also used : ArrayList(java.util.ArrayList) Component(com.janfic.games.computercombat.model.Component) SwitchAnimation(com.janfic.games.computercombat.model.animations.SwitchAnimation)

Example 2 with SwitchAnimation

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

the class SwitchComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove useAbility = (UseAbilityMove) move;
    Component[][] newBoard = state.componentBoard;
    Component a = useAbility.getSelectedComponents().get(0);
    Component b = useAbility.getSelectedComponents().get(1);
    Component bb = newBoard[b.getX()][b.getY()];
    Component ba = newBoard[a.getX()][a.getY()];
    bb.invalidate();
    ba.invalidate();
    ba.invalidateNeighbors();
    bb.invalidateNeighbors();
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    List<MoveAnimation> anims = new ArrayList<>();
    anims.add(new ConsumeProgressAnimation(move.getPlayerUID(), drained));
    anims.add(new SwitchAnimation(bb, ba));
    MoveResult r = new MoveResult(move, MatchState.record(state), anims);
    List<MoveResult> collectCheckResults = state.results(move);
    results.add(r);
    results.addAll(collectCheckResults);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) SwitchAnimation(com.janfic.games.computercombat.model.animations.SwitchAnimation) Card(com.janfic.games.computercombat.model.Card)

Aggregations

Component (com.janfic.games.computercombat.model.Component)2 SwitchAnimation (com.janfic.games.computercombat.model.animations.SwitchAnimation)2 ArrayList (java.util.ArrayList)2 Card (com.janfic.games.computercombat.model.Card)1 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1