From 153e9f4e502e514dad7336d044f45aab639d8766 Mon Sep 17 00:00:00 2001 From: howiieb Date: Sun, 3 May 2020 20:48:27 +0100 Subject: [PATCH] Can pick random battlecry type --- src/CardBuilder.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/CardBuilder.java b/src/CardBuilder.java index dd58e44..faf8ecd 100644 --- a/src/CardBuilder.java +++ b/src/CardBuilder.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; -import java.util.HashMap; public class CardBuilder { @@ -136,14 +135,14 @@ private CardText writeCardDraw(double budget, MinionType type) { return new CardText(effectText, effectCost); } - private CardText writeDealDamage(double budget, MinionType type){ + private CardText writeDealDamage(double budget, boolean alwaysRandom){ double effectCost = 0; String effectText = ""; while(effectCost > budget - 1 || effectCost == 0) { // Making sure we do this within the cost *and* leave at least one mana left effectText = ""; int damage = rng.nextInt(8) + 1; effectText = effectText.concat("deal ").concat(Integer.toString(damage)).concat(" damage "); - if (rng.nextBoolean()) { // Roll to decide if we attack random targets or a fixed target + if (rng.nextBoolean() || alwaysRandom) { // Roll to decide if we attack random targets or a fixed target switch (rng.nextInt(3)){ // 0 = enemy, 1 = enemy minion, 2 = enemy hero case 0: effectCost = damage; @@ -173,6 +172,17 @@ private CardText writeDealDamage(double budget, MinionType type){ return new CardText(effectText,effectCost); } + private CardText writeRandomEffect(double budget, MinionType type, boolean alwaysRandom){ + switch(rng.nextInt(2)){ + case 0: + return this.writeCardDraw(budget, type); + case 1: + return this.writeDealDamage(budget, alwaysRandom); + default: + return new CardText("",0); + } + } + /* CARD MAKERS */ // Creates a card with just stats, no description @@ -201,7 +211,7 @@ private Card makeBattlecryCard() { card.addToText(condText); // Add it to the text card.spendBudget(costToAdd); // Give additional budget points for the effect - CardText cardText = this.writeDealDamage(card.getBudget(),this.saneType(card.getType())); // Generate the card drawing text (50/50 chance of drawing the conditional type) + CardText cardText = this.writeRandomEffect(card.getBudget(), card.getType(), false); // Generate the card drawing text (50/50 chance of drawing the conditional type) card.addToText(cardText.getText()); // Add the effect to the text card.spendBudget(cardText.getCost()); // Spend how much that cost on the card's budget }