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");
}
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;
}
}
}
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);
}
}
}
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);
}
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;
}
Aggregations