Search in sources :

Example 26 with Card

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

the class SQLAPI method readCardFromSet.

private Card readCardFromSet(ResultSet set, String uid) {
    try {
        Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
        a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
        Collection collection = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
        String name = set.getString("card.name");
        String textureName = set.getString("card.textureName");
        int level = set.getInt("card.level");
        int id = set.getInt("card.id");
        int maxHealth = set.getInt("card.maxHealth");
        int maxDefense = set.getInt("card.maxDefense");
        int maxAttack = set.getInt("card.maxAttack");
        int runRequirements = set.getInt("card.runRequirements");
        int rarity = set.getInt("card.rarity");
        String description = set.getString("card.description");
        String components = set.getString("components");
        String[] c = components.split(",");
        int[] componentTypes = new int[c.length];
        for (int i = 0; i < c.length; i++) {
            componentTypes[i] = Integer.parseInt(c[i]);
        }
        Card s = new Card(id, uid, name, collection, textureName, level, maxHealth, maxDefense, maxAttack, 1, componentTypes, runRequirements, a, rarity, description);
        return s;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Ability(com.janfic.games.computercombat.model.Ability) Collection(com.janfic.games.computercombat.model.Collection) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) Card(com.janfic.games.computercombat.model.Card)

Example 27 with Card

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

the class SQLAPI method getCardById.

public Card getCardById(int id, String optionalUID) {
    System.out.println("[SERVER][MYSQL]: Querying for Card Data");
    try {
        String sql = "SELECT * FROM card \n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN run_requirements ON card.id = run_requirements.card_id\n" + "JOIN components ON components.id = run_requirements.component_id\n" + "JOIN collection ON card.collection_id = collection.id\n" + "WHERE card.id = '" + id + "';";
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        set.next();
        Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
        a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
        Collection c = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
        List<Integer> components = new ArrayList<>();
        String name = set.getString("card.name");
        String textureName = set.getString("card.textureName");
        int level = set.getInt("card.level");
        int maxHealth = set.getInt("card.maxHealth");
        int maxDefense = set.getInt("card.maxDefense");
        int maxAttack = set.getInt("card.maxAttack");
        int runRequirements = set.getInt("card.runRequirements");
        int rarity = set.getInt("card.rarity");
        String description = set.getString("card.description");
        do {
            components.add(set.getInt("components.id"));
        } while (set.next());
        int[] componentTypes = new int[components.size()];
        for (int i = 0; i < components.size(); i++) {
            componentTypes[i] = components.get(i);
        }
        Card s = new Card(id, optionalUID, name, c, textureName, level, maxHealth, maxDefense, maxAttack, 1, componentTypes, runRequirements, a, rarity, description);
        return s;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Ability(com.janfic.games.computercombat.model.Ability) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Collection(com.janfic.games.computercombat.model.Collection) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) Card(com.janfic.games.computercombat.model.Card)

Example 28 with Card

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

the class SQLAPI method getDeck.

public Deck getDeck(int deckID, String uid) {
    try {
        String sql = "SELECT * FROM deck\n" + "WHERE deck.profile_id = '" + uid + "' AND deck.id = '" + deckID + "';";
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        if (set.next() == false) {
            return null;
        }
        Deck deck = new Deck(set.getString("deck.name"), deckID);
        sql = "SELECT * FROM deck_has_card \n" + "JOIN card ON deck_has_card.card_id = card.id\n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN join_components ON join_components.card = card.id\n" + "JOIN collection ON card.collection_id = collection.id\n" + "WHERE deck_has_card.deck_id = '" + deckID + "';";
        set = statement.executeQuery(sql);
        boolean areRowsLeft = set.next();
        while (areRowsLeft) {
            Card c = readCardFromSet(set, uid);
            int amount = set.getInt("deck_has_card.amount");
            deck.addCard(c, amount);
            areRowsLeft = set.next();
        }
        return deck;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Deck(com.janfic.games.computercombat.model.Deck) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) Card(com.janfic.games.computercombat.model.Card)

Example 29 with Card

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

the class CollectAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Map<String, ComputerActor> computerActors = screen.getComputerActors();
    Map<String, List<SoftwareActor>> softwareActors = screen.getSoftwareActors();
    Board board = screen.getBoard();
    List<List<Action>> actions = new ArrayList<>();
    List<Action> popAction = new ArrayList<>();
    List<ComponentActor> componentActors = board.getComponents();
    for (Component component : getAllComponents()) {
        for (ComponentActor componentActor : componentActors) {
            if (componentActor.getComponent().equals(component)) {
                boolean isPlayerMove = currentPlayerUID.equals(playerUID);
                Action a = Actions.sequence(Actions.fadeOut(0.35f * animationSpeed), Actions.delay(0.35f * animationSpeed), Actions.moveTo(isPlayerMove ? 0 : board.getWidth() - 7 - 24, (8 - (componentActor.getComponent().getY() + 1)) * 24 + 7, (isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 6f * animationSpeed));
                a.setActor(componentActor);
                componentActor.setZIndex(0);
                Action b = Actions.sequence(Actions.fadeOut(0), Actions.visible(true), Actions.fadeIn(0.7f * animationSpeed), Actions.fadeOut((isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 6f * animationSpeed, Interpolation.fade));
                b.setActor(componentActor.getCollectedRegion());
                Image collectedComponent = new Image(board.getSkin(), "collected_component");
                board.getStage().addActor(collectedComponent);
                collectedComponent.setColor(board.getSkin().getColor(component.getTextureName().toUpperCase()).cpy().mul(1, 1, 1, 0));
                collectedComponent.setZIndex(10);
                int i = 4;
                final ComputerActor computerActor = computerActors.get(currentPlayerUID);
                SoftwareActor tempActor = null;
                if (progress.containsKey(component.toString())) {
                    Card c = progress.get(component.toString());
                    for (int j = 0; j < softwareActors.get(currentPlayerUID).size(); j++) {
                        SoftwareActor softwareActor = softwareActors.get(currentPlayerUID).get(j);
                        if (c.equals(softwareActor.getSoftware())) {
                            tempActor = softwareActor;
                            i = j;
                            break;
                        }
                    }
                }
                final SoftwareActor progressActor = tempActor;
                Vector2 start = new Vector2(isPlayerMove ? -5 : board.getWidth() + 3, (8 - (componentActor.getComponent().getY() + 1)) * 24 + 7 + 12 - 4);
                start = board.localToStageCoordinates(start);
                Vector2 end = board.localToStageCoordinates(new Vector2(isPlayerMove ? -5 : board.getWidth() + 3, gutterYs[i]));
                collectedComponent.setPosition(start.x, start.y);
                Action c = Actions.sequence(Actions.delay(animationSpeed * (isPlayerMove ? componentActor.getComponent().getX() : 7 - componentActor.getComponent().getX()) / 4f + 0.7f - 0.2f), Actions.scaleTo(1, 4 * animationSpeed), Actions.fadeIn(0.2f * animationSpeed), Actions.parallel(Actions.moveTo(end.x, end.y, Math.abs(end.y - start.y) / 100f * animationSpeed, Interpolation.exp5), Actions.sequence(Actions.scaleTo(1, 10, Math.abs(end.y - start.y) / 200f * animationSpeed, Interpolation.circleIn), Actions.scaleTo(1, 1, Math.abs(end.y - start.y) / 200f * animationSpeed, Interpolation.circleOut))), Actions.parallel(Actions.moveBy(isPlayerMove ? -13 : 13, 0, 0.1f * animationSpeed, Interpolation.exp5), Actions.scaleTo(2, 1, 0.1f * animationSpeed)), Actions.fadeOut(0.1f * animationSpeed), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        if (progressActor == null) {
                            computerActor.getComputer().recieveProgress(1);
                            computerActor.addProgress(1);
                        } else {
                            progressActor.getSoftware().recieveProgress(1);
                            for (Actor actor : progressActor.getLEDs().getChildren()) {
                                LEDActor led = (LEDActor) actor;
                                if (led.getComponentColor().equals(SoftwareActor.components.get(component.getColor()))) {
                                    led.setLightOn(true);
                                }
                            }
                        }
                    }
                }), Actions.delay(0.5f * animationSpeed), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        if (progressActor != null) {
                            for (Actor actor : progressActor.getLEDs().getChildren()) {
                                LEDActor led = (LEDActor) actor;
                                if (led.getComponentColor().equals(SoftwareActor.components.get(component.getColor()))) {
                                    led.setLightOn(false);
                                }
                            }
                        }
                    }
                }), Actions.removeActor());
                c.setActor(collectedComponent);
                popAction.add(a);
                popAction.add(b);
                popAction.add(c);
            }
        }
    }
    actions.add(popAction);
    return actions;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Card(com.janfic.games.computercombat.model.Card) Board(com.janfic.games.computercombat.actors.Board) Vector2(com.badlogic.gdx.math.Vector2) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) LEDActor(com.janfic.games.computercombat.actors.LEDActor) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) LEDActor(com.janfic.games.computercombat.actors.LEDActor) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component) ComponentActor(com.janfic.games.computercombat.actors.ComponentActor)

Example 30 with Card

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

the class DrawAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Table leftPanel = screen.getLeftPanel();
    Table rightPanel = screen.getRightPanel();
    Table panel;
    if (playerUID.equals(currentPlayerUID)) {
        panel = leftPanel;
    } else {
        panel = rightPanel;
    }
    List<List<Action>> animations = new ArrayList<>();
    ComputerCombatGame game = (ComputerCombatGame) Gdx.app.getApplicationListener();
    if (newSoftware.size() > 0) {
        List<Action> cardAnimation = new ArrayList<>();
        Table t = new Table();
        t.setFillParent(true);
        Card loadNewCard = SQLAPI.getSingleton().getCardById(newSoftware.get(0).getID(), newSoftware.get(0).getOwnerUID());
        loadNewCard.setMatchID(newSoftware.get(0).getMatchID());
        CollectionCard card = new CollectionCard(game, screen.getSkin(), loadNewCard, 1);
        card.setTouchable(Touchable.disabled);
        Stage stage = screen.getMainStage();
        stage.addActor(t);
        card.setVisible(false);
        card.setPosition(stage.getWidth() / 2, -300);
        t.add(card).expand().center();
        Action cardAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow), Actions.delay(1 * animationSpeed), Actions.moveBy(0, -400, 1 * animationSpeed, Interpolation.slowFast));
        cardAction.setActor(card);
        cardAnimation.add(cardAction);
        animations.add(cardAnimation);
        List<SoftwareActor> softwareActors = screen.getSoftwareActors().get(currentPlayerUID);
        ComputerActor computerActor = screen.getComputerActors().get(currentPlayerUID);
        List<Action> softwareAnimation = new ArrayList<>();
        SoftwareActor softwareActor = new SoftwareActor(screen.getSkin(), !playerUID.equals(currentPlayerUID), loadNewCard, game);
        panel.clear();
        for (SoftwareActor s : softwareActors) {
            panel.add(s).row();
        }
        panel.add(softwareActor).row();
        panel.add(computerActor).expandY().growX().bottom();
        softwareActor.setVisible(false);
        softwareActors.add(softwareActor);
        Action softwareActorAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow));
        softwareActorAction.setActor(softwareActor);
        softwareAnimation.add(softwareActorAction);
        animations.add(softwareAnimation);
    }
    return animations;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ArrayList(java.util.ArrayList) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) ComputerCombatGame(com.janfic.games.computercombat.ComputerCombatGame) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ArrayList(java.util.ArrayList) List(java.util.List)

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