Search in sources :

Example 1 with Card

use of lcm2.cards.Card in project cardgame1 by joey101937.

the class CampaignManager method saveGame.

/**
 * saves game to save game file
 */
public static void saveGame() {
    System.out.println("Saving Game...");
    File output = new File(fileName);
    if (output.exists())
        output.delete();
    ArrayList<String> lines = new ArrayList<>();
    lines.add(String.valueOf(level));
    lines.add(playerClass.toString());
    for (Card c : playerCards) {
        lines.add(c.name);
    }
    try {
        FileWriter fw = new FileWriter(output, false);
        BufferedWriter bw = new BufferedWriter(fw);
        for (String s : lines) {
            bw.write(s);
            System.out.println("writing... " + s);
            bw.newLine();
        }
        bw.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Game Save Complete");
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) NoSuchCardException(CustomDecks.NoSuchCardException) FileNotFoundException(java.io.FileNotFoundException) CorruptFileException(CustomDecks.CorruptFileException) IOException(java.io.IOException) DoubleshotCard(Cards.Empire.DoubleshotCard) DragonSoulTrapCard(Cards.Dragon.DragonSoulTrapCard) CustomDeck.getCard(CustomDecks.CustomDeck.getCard) GrayDrakeCard(Cards.Dragon.GrayDrakeCard) SnipeTrapCard(Cards.Empire.SnipeTrapCard) SwollowCard(Cards.Fish.SwollowCard) CavalryGeneralCard(Cards.Empire.CavalryGeneralCard) ApocalypseCard(Cards.Empire.ApocalypseCard) GriffonCard(Cards.Empire.GriffonCard) Card(Cards.Card) JellyfishCard(Cards.Fish.JellyfishCard) SkelemancerCard(Cards.Undead.SkelemancerCard) PredationCard(Cards.Fish.PredationCard) SkullKingCard(Cards.Undead.SkullKingCard) SeaWitchCard(Cards.Fish.SeaWitchCard) ZombieTrapCard(Cards.Undead.ZombieTrapCard) VolcanicDrakeCard(Cards.Dragon.VolcanicDrakeCard) EnchantedSwordCard(Cards.Empire.EnchantedSwordCard) SeaSerpentTrapCard(Cards.Fish.SeaSerpentTrapCard) FireyWhelpCard(Cards.Empire.FireyWhelpCard) DragonBreathCard(Cards.Dragon.DragonBreathCard) ThrasherCard(Cards.Fish.ThrasherCard) PirranahCard(Cards.Fish.PirranahCard) BufferedWriter(java.io.BufferedWriter)

Example 2 with Card

use of lcm2.cards.Card in project cardgame1 by joey101937.

the class CardAdderPanel method drawCards.

/*
     *Player chooses 3 cards per win
     *First 2 are Class cards
     *Third is Neutral
     */
public void drawCards(Graphics2D g) {
    g.scale(1, 1);
    g.setFont(new Font("Arial", Font.BOLD, 35));
    for (int i = 0; i < 4; i++) {
        try {
            Card toDraw = host.currentSelection.get(i);
            if (toDraw == null)
                continue;
            toDraw.render(g, 20 + 220 * i, 200, true);
        } catch (IndexOutOfBoundsException ex) {
            continue;
        }
    }
}
Also used : Font(java.awt.Font) Card(Cards.Card)

Example 3 with Card

use of lcm2.cards.Card in project cardgame1 by joey101937.

the class AI method goForLethal.

/**
 * has all available minons attack the opponent's hero and plays available
 * charge minoins and direct damage for the face
 * @param h hero we are playing for
 */
public static void goForLethal(Hero h) {
    if (getTotalDamagePotential(h) < h.opponent.health) {
        System.out.println("Trying to go for lethal without enough damage potential (required " + h.opponent.health + ")");
        return;
    }
    for (Minion m : h.minions.getOccupants()) {
        Main.wait(AI.speed);
        if (m.canAttack())
            m.attack(h.opponent);
    }
    ArrayList<Card> potentialDirect = new ArrayList<Card>();
    for (Card c : h.hand) {
        if ((c.cardPurpose == CardPurpose.DirectDamage && c.damagesHeros) || c.cardPurpose == CardPurpose.ChargeMinion) {
            if (!c.canAfford())
                continue;
            potentialDirect.add(c);
        }
    }
    potentialDirect.sort(null);
    int resources = h.resource;
    int i = 0;
    for (Card c : potentialDirect) {
        if (c.cost > resources)
            break;
        resources -= c.cost;
        if (c.cardPurpose == CardPurpose.Trap) {
            // let user know we are playing a trap card
            Sticker s = new Sticker(SpriteHandler.trapPlaceholder, 1700, 200, speed * 3);
        } else {
            // let user know what non-trap card we are playing
            Sticker s = new Sticker(c, 1700, 200, speed * 3);
        }
        Main.wait(speed * 3);
        if (c.isTargeted) {
            System.out.println("Casting card " + c + " on hero for lethal");
            c.castOnHero(h.opponent);
        } else {
            System.out.println("Casting card " + c + " on null for lethal");
            c.cast(null);
        }
    }
}
Also used : Sticker(cardgame1.Sticker) Minion(Minions.Minion) ArrayList(java.util.ArrayList) Card(Cards.Card)

Example 4 with Card

use of lcm2.cards.Card in project cardgame1 by joey101937.

the class AI method playOutHand.

/**
 * plays all cards we can in the best way possible, recursively
 * @param h hero we are playing for
 */
public static void playOutHand(Hero h) {
    if (h.opponent.health <= 0)
        return;
    Board.getMainBoard().tick();
    boolean playOver = true;
    for (Card c : h.hand) {
        // there is something we want to play
        if (c.canAfford() && AI.getValueOfCard(c) > 0)
            playOver = false;
    }
    if (playOver)
        return;
    ArrayList<Card> playable = new ArrayList<>();
    for (Card c : h.hand) {
        if (c.canAfford() && getValueOfCard(c) > 0)
            playable.add(c);
    }
    // orders the cards using their comparable interface, ordering based on value rather than worth (value accounts for cost, worth does not)
    playable.sort(null);
    if (playable.get(playable.size() - 1).cardPurpose == CardPurpose.Trap) {
        // let user know we are playing a trap card
        Sticker s = new Sticker(SpriteHandler.trapPlaceholder, 1700, 200, speed * 3);
    } else {
        // let user know what non-trap card we are playing
        Sticker s = new Sticker(playable.get(playable.size() - 1), 1700, 200, speed * 3);
    }
    Main.wait(speed * 3);
    System.out.println("attempting to play: " + playable.get(playable.size() - 1));
    AI.playCard(playable.get(playable.size() - 1));
    playOutHand(h);
}
Also used : Sticker(cardgame1.Sticker) ArrayList(java.util.ArrayList) Card(Cards.Card)

Example 5 with Card

use of lcm2.cards.Card in project cardgame1 by joey101937.

the class AI method getWorth.

/**
 * calculates the worth of a minion for purposes of making plays
 * @param m minion to evaluate
 * @return how much a minion is worth, higher is better
 */
public static int getWorth(Minion m) {
    int sumStats = m.health + m.attack;
    sumStats += m.intrinsicValue;
    // low attack is slightly worse than high atk
    if (m.attack < m.health)
        sumStats--;
    if (m.health <= 0) {
        // worthless if dead
        return 0;
    }
    if (m.owner.minions.isFull()) {
        for (Minion min : m.owner.minions.getStorage()) {
            if (min != null && sumStats > min.attack + min.health) {
                return sumStats;
            }
        }
        // this is the smallest minion on a full field
        for (Card c : m.owner.hand) {
            if (c.canAfford() && c.cardType == CardType.Minion && (c.summon.attack + c.summon.health + c.intrinsicValue) > sumStats) {
                // the minion is taking a slot that a largert minion should have
                return 0;
            }
        }
    }
    return sumStats;
}
Also used : Minion(Minions.Minion) Card(Cards.Card)

Aggregations

Card (Cards.Card)39 Card (lcm2.cards.Card)27 ArrayList (java.util.ArrayList)14 Action (lcm2.simulation.Action)9 Minion (Minions.Minion)8 Dimension (java.awt.Dimension)6 SpearmanCard (Cards.Base.SpearmanCard)4 GeomancerCard (Cards.Elemental.GeomancerCard)4 SandElementalCard (Cards.Elemental.SandElementalCard)4 SorcererCard (Cards.Elemental.SorcererCard)4 StoneGolemCard (Cards.Elemental.StoneGolemCard)4 ApocalypseCard (Cards.Empire.ApocalypseCard)4 IOException (java.io.IOException)4 CorruptFileException (CustomDecks.CorruptFileException)3 Board (cardgame1.Board)3 Hero (cardgame1.Hero)3 DragonBreathCard (Cards.Dragon.DragonBreathCard)2 DragonSoulTrapCard (Cards.Dragon.DragonSoulTrapCard)2 GrayDrakeCard (Cards.Dragon.GrayDrakeCard)2 VolcanicDrakeCard (Cards.Dragon.VolcanicDrakeCard)2