Search in sources :

Example 16 with Card

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

the class DamageHeuristicAnalyzer method getTotalHealths.

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

Example 17 with Card

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

the class OpenPackScreen method show.

@Override
public void show() {
    this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
    this.stage = ComputerCombatGame.makeNewStage(camera);
    this.skin = game.getAssetManager().get(Assets.SKIN);
    this.collections = SQLAPI.getSingleton().getCollections();
    List<Integer> collectionIDs = new ArrayList<>();
    collectionIDs.add(collection.getID());
    if (collection.getID() == 0) {
        for (Collection c : collections) {
            collectionIDs.add(c.getID());
        }
    }
    collectionIDs.remove((Integer) 0);
    this.collectionCards = SQLAPI.getSingleton().getCardsInCollection(collectionIDs, game.getCurrentProfile().getUID());
    System.out.println(collectionCards);
    this.pack = new CollectionPackActor(game, skin, collection);
    pack.setScale(1.25f);
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    table.setFillParent(true);
    table.defaults().space(20);
    TextButton openButton = new TextButton("Open!", skin);
    openButton.setTouchable(Touchable.disabled);
    List<Card> openCards = new ArrayList<>();
    openCards.add(roll());
    openCards.add(roll());
    openCards.add(roll());
    end = new TextButton("Okay", skin);
    end.setVisible(false);
    end.setPosition(10, 10);
    end.setSize(100, 30);
    end.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            Map<Integer, Integer> added = new HashMap<>();
            for (Card openCard : openCards) {
                added.put(openCard.getID(), added.getOrDefault(openCard.getID(), 0) + 1);
            }
            SQLAPI.getSingleton().addCardsToProfile(added, game.getCurrentProfile());
            SQLAPI.getSingleton().saveProfile(game.getCurrentProfile());
            game.popScreen();
        }
    });
    table.add(pack).row();
    table.add(openButton).width(100).row();
    Action cardAction = Actions.sequence(Actions.visible(false), Actions.delay(1), Actions.moveBy(0, -stage.getHeight() * 2), Actions.visible(true), Actions.moveBy(0, stage.getHeight() * 2, 2, Interpolation.fastSlow), Actions.delay(2));
    Action buttonAction = Actions.sequence(Actions.fadeOut(0), Actions.delay(3), Actions.fadeIn(1), Actions.touchable(Touchable.enabled));
    openButton.addAction(buttonAction);
    pack.addAction(cardAction);
    cardActors = new ArrayList<>();
    openButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            pack.open();
            openButton.setVisible(false);
            Action open = Actions.sequence(Actions.moveBy(0, -200, 1), Actions.run(() -> {
                confetti();
                for (CollectionCard openCard : cardActors) {
                    openCard.setPosition(pack.getX(), pack.getY());
                    openCard.setSize(pack.getWidth() - 4, pack.getHeight());
                    openCard.addAction(Actions.parallel(Actions.moveBy(0, 200, 1, Interpolation.circleOut), Actions.moveBy((cardActors.indexOf(openCard) - 1) * 150, 0, 1, Interpolation.circleIn)));
                }
            }), Actions.run(() -> {
                end.setVisible(true);
            }));
            pack.addAction(open);
        }
    });
    for (Card openCard : openCards) {
        CollectionCard c = new CollectionCard(game, skin, openCard, 1);
        cardActors.add(c);
        stage.addActor(c);
    }
    stage.addActor(table);
    stage.addActor(end);
    table.layout();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Action(com.badlogic.gdx.scenes.scene2d.Action) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ArrayList(java.util.ArrayList) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) CollectionPackActor(com.janfic.games.computercombat.actors.CollectionPackActor) Collection(com.janfic.games.computercombat.model.Collection) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) HashMap(java.util.HashMap) Map(java.util.Map) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 18 with Card

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

the class OpenPackScreen method roll.

public Card roll() {
    int r = (int) (Math.random() * 5 * 5 * 5) + 1;
    int selectedRarity = 1;
    for (int i = 1; i <= 5; i++) {
        selectedRarity = i;
        if (i * i * i >= r) {
            break;
        }
    }
    List<Card> pool = new ArrayList<>();
    for (Card card : collectionCards) {
        if (card.getRarity() == selectedRarity) {
            pool.add(card);
        }
    }
    Collections.shuffle(pool);
    return pool.get(0);
}
Also used : ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard)

Example 19 with Card

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

the class CollectionScreen method buildCollection.

public void buildCollection() {
    Profile profile = game.getCurrentProfile();
    Map<Card, Integer> playerCards = new HashMap<>();
    Map<Card, Integer> allCards = new HashMap<>();
    List<Card> ac = SQLAPI.getSingleton().getCardsInfo(null, null);
    playerCards = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    for (Card card : ac) {
        for (Card c : playerCards.keySet()) {
            if (card.getID() == c.getID()) {
                card.setOwnerUID(profile.getUID());
                break;
            }
        }
    }
    for (Card card : ac) {
        allCards.put(card, 0);
    }
    for (Card card : playerCards.keySet()) {
        allCards.put(card, playerCards.get(card));
    }
    collection.clearChildren();
    int row = 0;
    for (Card card : allCards.keySet()) {
        CollectionCard cc = new CollectionCard(game, skin, card, allCards.get(card));
        if (allCards.get(card) == 0) {
            cc.setColor(1, 1, 1, 0.5f);
        }
        if (filterWindow.getFilter().filter(card, null, null)) {
            cards.add(cc);
            collection.add(cc);
            row++;
            if (row % 4 == 0) {
                collection.row();
                row = 0;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Profile(com.janfic.games.computercombat.model.Profile) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card)

Example 20 with Card

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

the class DecksScreen method buildCollection.

public void buildCollection() {
    Profile profile = game.getCurrentProfile();
    software = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    collection.clearChildren();
    int row = 0;
    for (Card card : software.keySet()) {
        Table cardTable = new Table();
        CollectionCard cc = new CollectionCard(game, skin, card, software.get(card));
        cardTable.add(cc).colspan(3).grow().row();
        TextButton addButton = new TextButton("+", skin) {

            @Override
            public void act(float delta) {
                // To change body of generated methods, choose Tools | Templates.
                super.act(delta);
                if (selectedDeck != null && selectedDeck.getDeck().getCardCount(card.getID()) >= software.get(card)) {
                    this.setColor(Color.RED);
                } else {
                    this.setColor(Color.WHITE);
                }
            }
        };
        addButton.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (selectedDeck != null) {
                    if (selectedDeck.getDeck().getCardCount(card.getID()) < software.get(card)) {
                        selectedDeck.getDeck().addCard(card, 1);
                        updateDeckCards();
                    }
                }
            }
        });
        TextButton removeButton = new TextButton("-", skin);
        removeButton.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (selectedDeck != null) {
                    selectedDeck.getDeck().removeCard(card, 1);
                    updateDeckCards();
                }
            }
        });
        Label amountInDeck = new Label("-", skin) {

            @Override
            public void act(float delta) {
                super.act(delta);
                if (selectedDeck != null) {
                    this.setText("" + selectedDeck.getDeck().getCardCount(card.getID()));
                } else {
                    this.setText("-");
                }
            }
        };
        cardTable.add(removeButton).expandX().width(30);
        cardTable.add(amountInDeck);
        cardTable.add(addButton).expandX().width(30);
        if (filterWindow.getFilter().filter(card, null, null)) {
            collection.add(cardTable);
            collectionToDeckDragAndDrop.addSource(new Source(cc) {

                @Override
                public Payload dragStart(InputEvent ie, float f, float f1, int i) {
                    Payload payload = new Payload();
                    payload.setObject(card);
                    BorderedArea dragActor = new BorderedArea(skin);
                    dragActor.setWidth(48);
                    dragActor.setHeight(48);
                    dragActor.add(new Image(game.getAssetManager().get("texture_packs/" + card.getCollection().getTextureName() + ".atlas", TextureAtlas.class).findRegion(card.getTextureName()))).width(46).height(46);
                    payload.setDragActor(dragActor);
                    return payload;
                }
            });
            row++;
            if (row % 2 == 0) {
                collection.row();
                row = 0;
            }
        }
    }
}
Also used : Profile(com.janfic.games.computercombat.model.Profile) Card(com.janfic.games.computercombat.model.Card) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

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