Search in sources :

Example 1 with SpawnAnimation

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

the class SpawnAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    MoveAnimation consumeProgressAnimation = Ability.consumeCardProgress(state, move);
    List<int[]> newCoords = new ArrayList<>();
    int amountSpawned = amount.analyze(state, move);
    for (int i = 0; i < amountSpawned; i++) {
        int[] newLocation = new int[] { (int) (Math.random() * 8), (int) (Math.random() * 8) };
        boolean duplicate = false;
        while (state.getComponentBoard()[newLocation[0]][newLocation[1]].getColor() == componentType || duplicate == true) {
            for (int[] newCoord : newCoords) {
                if (newLocation[0] == newCoord[0] && newLocation[1] == newCoord[1]) {
                    duplicate = true;
                    break;
                }
            }
            newLocation = new int[] { (int) (Math.random() * 8), (int) (Math.random() * 8) };
        }
        newCoords.add(newLocation);
    }
    List<Component> spawned = new ArrayList<>();
    List<Component> destroyed = new ArrayList<>();
    for (int[] newCoord : newCoords) {
        Component destroy = state.getComponentBoard()[newCoord[0]][newCoord[1]];
        Component spawn = new Component(componentType, newCoord[0], newCoord[1]);
        state.getComponentBoard()[newCoord[0]][newCoord[1]].changeColor(spawn.getColor());
        state.getComponentBoard()[newCoord[0]][newCoord[1]].invalidate();
        state.getComponentBoard()[newCoord[0]][newCoord[1]].invalidateNeighbors();
        spawned.add(spawn);
        destroyed.add(destroy);
    }
    List<MoveAnimation> animations = new ArrayList<>();
    if (consumeProgressAnimation != null) {
        animations.add(consumeProgressAnimation);
    }
    animations.add(new SpawnAnimation(destroyed, spawned));
    MoveResult moveResult = new MoveResult(move, MatchState.record(state), animations);
    List<MoveResult> afterMove = state.results(move);
    results.add(moveResult);
    results.addAll(afterMove);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) SpawnAnimation(com.janfic.games.computercombat.model.animations.SpawnAnimation)

Example 2 with SpawnAnimation

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

the class TransformComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    Component[][] board = state.getComponentBoard();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Component> originalComponents = new ArrayList<>(), newComponents = new ArrayList<>();
    for (Component[] components : board) {
        for (Component component : components) {
            if (filter.filter(component, state, move)) {
                int randomIndex = (int) (Math.random() * transformTypes.size());
                Component c = new Component(transformTypes.get(randomIndex), component.getX(), component.getY());
                originalComponents.add(new Component(component));
                newComponents.add(c);
                board[component.getX()][component.getY()].changeColor(transformTypes.get(randomIndex));
                board[component.getX()][component.getY()].invalidate();
                board[component.getX()][component.getY()].invalidateNeighbors();
            }
        }
    }
    animations.add(consumeProgress);
    animations.add(new SpawnAnimation(originalComponents, newComponents));
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    List<MoveResult> afterMove = state.results(move);
    results.add(result);
    results.addAll(afterMove);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) SpawnAnimation(com.janfic.games.computercombat.model.animations.SpawnAnimation)

Aggregations

Component (com.janfic.games.computercombat.model.Component)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)2 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)2 ArrayList (java.util.ArrayList)2