Search in sources :

Example 36 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class AttackAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    String currentUID = move.getPlayerUID();
    String opponentUID = state.getOtherProfile(state.currentPlayerMove);
    List<Card> destroyed = new ArrayList<>();
    List<MoveAnimation> animation = new ArrayList<>();
    for (String key : attacks.keySet()) {
        Array<Integer> attacked = attacks.get(key);
        for (Integer c : attacked) {
            Card att = state.getCardMyMatchID(Integer.parseInt(key));
            if (att.getID() > 0) {
                for (Card cardAttacked : state.activeEntities.get(opponentUID)) {
                    if (c == cardAttacked.getMatchID()) {
                        cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
                        animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
                        if (cardAttacked.isDead()) {
                            destroyed.add(cardAttacked);
                        }
                        break;
                    }
                }
            } else if (att.getID() == 0) {
                Card cardAttacked = state.computers.get(opponentUID);
                cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
                animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
            }
        }
    }
    MoveResult result = new MoveResult(move, MatchState.record(state), animation);
    results.add(result);
    if (!destroyed.isEmpty()) {
        DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
        List<MoveResult> r = destroyAbility.doAbility(state, move);
        results.addAll(r);
    }
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) AttackAnimation(com.janfic.games.computercombat.model.animations.AttackAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 37 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class DamageAllAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> destroyed = new ArrayList<>();
    List<MoveAnimation> animation = new ArrayList<>();
    int index = state.activeEntities.get(abilityMove.getCard().getOwnerUID()).indexOf(abilityMove.getCard());
    state.activeEntities.get(abilityMove.getPlayerUID()).get(index).setProgress(0);
    for (Card card : state.getAllCards()) {
        if (filter == null || filter.filter(card, state, move)) {
            int damage = amount.analyze(state, move);
            animation.add(new ReceiveDamageAnimation(card, damage, card.getOwnerUID()));
            card.recieveDamage(damage);
            if (card.isDead()) {
                destroyed.add(card);
            }
        }
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animation);
    results.add(result);
    if (destroyed.isEmpty() == false) {
        DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
        List<MoveResult> r = destroyAbility.doAbility(state, move);
        results.addAll(r);
    }
    List<Card> drained = new ArrayList<>();
    drained.add(((UseAbilityMove) (move)).getCard());
    results.get(0).getAnimations().add(0, new ConsumeProgressAnimation(move.getPlayerUID(), drained));
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ReceiveDamageAnimation(com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card)

Example 38 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class MatchState method clone.

@Override
public Object clone() throws CloneNotSupportedException {
    Player player1 = (Player) players.get(0).clone();
    Player player2 = (Player) players.get(1).clone();
    Component[][] componentBoard = new Component[8][8];
    for (int x = 0; x < componentBoard.length; x++) {
        for (int y = 0; y < componentBoard[x].length; y++) {
            componentBoard[x][y] = new Component(this.componentBoard[x][y]);
        }
    }
    Map<String, List<Card>> activeEntities = new HashMap<>();
    List<Card> player1Cards = new ArrayList<>();
    List<Card> player2Cards = new ArrayList<>();
    activeEntities.put(player1.getUID(), player1Cards);
    activeEntities.put(player2.getUID(), player2Cards);
    for (String string : this.activeEntities.keySet()) {
        for (Card card : this.activeEntities.get(string)) {
            activeEntities.get(string).add((Card) (card.clone()));
        }
    }
    Map<String, Deck> decks = new HashMap<>();
    for (String uid : this.decks.keySet()) {
        decks.put(uid, (Deck) this.decks.get(uid).clone());
    }
    Map<String, Card> computers = new HashMap<>();
    for (String uid : this.computers.keySet()) {
        computers.put(uid, (Card) this.computers.get(uid).clone());
    }
    MatchState state = new MatchState(player1, player2, componentBoard, activeEntities, computers, decks);
    state.isGameOver = this.isGameOver;
    if (this.winner != null) {
        state.winner = "" + this.winner;
    }
    state.currentPlayerMove = "" + this.currentPlayerMove;
    MatchState.buildNeighbors(componentBoard);
    state.update();
    return state;
}
Also used : Player(com.janfic.games.computercombat.model.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component)

Example 39 with Card

use of com.janfic.games.computercombat.model.Card 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)

Example 40 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class ChargeAbilitiesHeuristicAnalyzer method getCharges.

public int getCharges(MoveResult result) {
    int totalCharge = 0;
    String currentUID = result.getMove().getPlayerUID();
    String opponentUID = result.getState().getOtherProfile(currentUID);
    for (Card card : result.getState().activeEntities.get(opponentUID)) {
        totalCharge += card.getRunProgress();
    }
    totalCharge += result.getState().computers.get(opponentUID).getRunProgress();
    return totalCharge;
}
Also used : Card(com.janfic.games.computercombat.model.Card)

Aggregations

Card (com.janfic.games.computercombat.model.Card)42 ArrayList (java.util.ArrayList)28 List (java.util.List)12 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)11 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)10 Action (com.badlogic.gdx.scenes.scene2d.Action)9 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)8 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)7 Component (com.janfic.games.computercombat.model.Component)6 ResultSet (java.sql.ResultSet)6 Statement (java.sql.Statement)6 HashMap (java.util.HashMap)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 Deck (com.janfic.games.computercombat.model.Deck)5 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)5 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)4 Collection (com.janfic.games.computercombat.model.Collection)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)3