Search in sources :

Example 1 with Card

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

the class MatchState method read.

@Override
public void read(Json json, JsonValue jsonData) {
    json.setTypeName("class");
    this.players = json.readValue("players", List.class, Player.class, jsonData);
    json.setTypeName(null);
    this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
    this.winner = json.readValue("winner", String.class, jsonData);
    this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
    this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
    HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
    this.activeEntities = new HashMap<>();
    for (String string : v.keySet()) {
        List<Card> cards = new ArrayList<>();
        for (JsonValue jsonValue : v.get(string)) {
            Card c = json.readValue(Card.class, jsonValue);
            cards.add(c);
        }
        activeEntities.put(string, cards);
    }
    this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
    String boardString = json.readValue("componentBoard", String.class, jsonData);
    componentBoard = new Component[8][8];
    assert (boardString.length() == 64);
    for (int i = 0; i < boardString.length(); i++) {
        int x = i / 8;
        int y = i % 8;
        try {
            componentBoard[x][y] = new Component(Integer.parseInt("" + boardString.substring(i, i + 1)), x, y);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    json.setTypeName("class");
}
Also used : Player(com.janfic.games.computercombat.model.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonValue(com.badlogic.gdx.utils.JsonValue) 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 2 with Card

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

the class MatchState method progress.

public void progress(CollectAnimation collectAnimation) {
    Map<Component, Card> progress = collectAnimation.progress;
    for (Component c : collectAnimation.getAllComponents()) {
        boolean collectedByCard = false;
        for (Card card : activeEntities.get(currentPlayerMove)) {
            if (card.getRunProgress() < card.getRunRequirements()) {
                for (Integer requirement : card.getRunComponents()) {
                    if (c.getColor() == requirement) {
                        card.recieveComponents(requirement, 1);
                        collectedByCard = true;
                        progress.put(c, card);
                        break;
                    }
                }
            }
            if (collectedByCard == true) {
                break;
            }
        }
        if (collectedByCard == false) {
            computers.get(currentPlayerMove).recieveProgress(1);
        }
    }
}
Also used : Component(com.janfic.games.computercombat.model.Component) Card(com.janfic.games.computercombat.model.Card)

Example 3 with Card

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

the class FocusedDamageAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> moveResults = new ArrayList<>();
    UseAbilityMove abilityMove = (UseAbilityMove) move;
    List<Card> destroyed = new ArrayList<>();
    List<MoveAnimation> animation = new ArrayList<>();
    MoveAnimation consume = Ability.consumeCardProgress(state, move);
    animation.add(consume);
    int index = state.activeEntities.get(abilityMove.getCard().getOwnerUID()).indexOf(abilityMove.getCard());
    state.activeEntities.get(abilityMove.getPlayerUID()).get(index).setProgress(0);
    for (Card selectedSoftware : abilityMove.getSelectedSoftwares()) {
        for (String playerUID : state.activeEntities.keySet()) {
            for (Card card : state.activeEntities.get(playerUID)) {
                if (card.equals(selectedSoftware)) {
                    int damage = amount.analyze(state, move);
                    card.recieveDamage(damage);
                    animation.add(new ReceiveDamageAnimation(selectedSoftware, damage, card.getOwnerUID()));
                    if (card.isDead()) {
                        destroyed.add(card);
                    }
                }
            }
        }
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animation);
    moveResults.add(result);
    if (destroyed.isEmpty() == false) {
        DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
        List<MoveResult> r = destroyAbility.doAbility(state, move);
        moveResults.addAll(r);
    }
    return moveResults;
}
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) Card(com.janfic.games.computercombat.model.Card)

Example 4 with Card

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

the class TransformCardAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Card> old = new ArrayList<>();
    List<Card> newC = new ArrayList<>();
    for (CardFilter filter : oldCards) {
        for (String uid : state.activeEntities.keySet()) {
            for (int i = 0; i < state.activeEntities.get(uid).size(); i++) {
                Card oldCard = state.activeEntities.get(uid).get(i);
                if (filter.filter(oldCard, state, move)) {
                    Card newCard = SQLAPI.getSingleton().getCardById(newCards.get(oldCards.indexOf(filter)), oldCard.getOwnerUID());
                    newCard.generateMatchID();
                    state.activeEntities.get(uid).set(i, newCard);
                    old.add(oldCard);
                    newC.add(newCard);
                }
            }
        }
    }
    if (consumeProgress != null) {
        animations.add(consumeProgress);
    }
    animations.add(new TransformCardAnimation(old, newC));
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    return results;
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) TransformCardAnimation(com.janfic.games.computercombat.model.animations.TransformCardAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 5 with Card

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

the class SQLAPI method getCardsInCollection.

public List<Card> getCardsInCollection(List<Integer> collectionIDs, String optionalUID) {
    List<Card> cards = new ArrayList<>();
    try {
        String sql = "SELECT * FROM card\n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN join_components ON card.id = join_components.card \n" + "JOIN collection ON card.collection_id = collection.id;";
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        boolean areRowsLeft = set.next();
        while (areRowsLeft) {
            if (collectionIDs.contains(set.getInt("card.collection_id")) && set.getInt("card.id") != 0) {
                Card c = readCardFromSet(set, optionalUID);
                cards.add(c);
            }
            areRowsLeft = set.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cards;
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) 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