Search in sources :

Example 6 with Collection

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

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

Aggregations

Collection (com.janfic.games.computercombat.model.Collection)7 Card (com.janfic.games.computercombat.model.Card)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 ArrayList (java.util.ArrayList)4 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)3 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)3 Ability (com.janfic.games.computercombat.model.Ability)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 CollectionPackActor (com.janfic.games.computercombat.actors.CollectionPackActor)2 HashMap (java.util.HashMap)2 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Action (com.badlogic.gdx.scenes.scene2d.Action)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)1