/** * getTokenCreatures. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getTokenCreatures(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isCreature() && c.isToken() && !c.isEquipped() && !c.isEnchanted()) ret.add(c); } return ret; }
/** * getPlaneswalkers. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getPlaneswalkers(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isPlaneswalker() && !c.isArtifact()) ret.add(c); } return ret; }
/** * When the player click the BET button, check the input validity and process. * * @param e */ @Override public void mouseClicked(MouseEvent e) { if (betButton.isEnabled()) { int bet = 0; try { bet = Integer.parseInt(betInput.getText()); if (bet <= 0 || bet > player.getMoney()) throw null; } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Invalid bet"); betInput.setText(null); betInput.requestFocusInWindow(); return; } int d1 = dealer.makeDecision(); if (d1 != -1) { dealer.changeCard(d1, genNewCard()); int d2 = dealer.makeDecision(); if (d2 != -1) dealer.changeCard(d2, genNewCard()); } player.makeBet(bet); for (Card card : player.getCards()) card.showFront(); for (Card card : player.getCards()) card.addMouseListener(new ReplaceListener()); betButton.setEnabled(false); resultButton.setEnabled(true); repaint(); } }
/** * getGlobalEnchantments. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getGlobalEnchantments(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isGlobalEnchantment() && !c.isCreature()) ret.add(c); } return ret; }
/** * getBasics. * * @param cards a {@link java.util.ArrayList} object. * @param color a {@link java.lang.String} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getBasics(ArrayList<Card> cards, String color) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { String name = c.getName(); if (c.isEnchanted()) ; // do nothing else if (name.equals("Swamp") || name.equals("Bog")) { if (color == Constant.Color.Black) { ret.add(c); } } else if (name.equals("Forest") || name.equals("Grass")) { if (color == Constant.Color.Green) { ret.add(c); } } else if (name.equals("Plains") || name.equals("White Sand")) { if (color == Constant.Color.White) { ret.add(c); } } else if (name.equals("Mountain") || name.equals("Rock")) { if (color == Constant.Color.Red) { ret.add(c); } } else if (name.equals("Island") || name.equals("Underwater")) { if (color == Constant.Color.Blue) { ret.add(c); } } } return ret; }
/** * getCard. * * @param cards a {@link java.util.ArrayList} object. * @param name a {@link java.lang.String} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getCard(ArrayList<Card> cards, String name) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.getName().equals(name)) ret.add(c); } return ret; }
/** * getNonBasicLand. * * @param cards a {@link java.util.ArrayList} object. * @param landName a {@link java.lang.String} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getNonBasicLand(ArrayList<Card> cards, String landName) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) if (c.getName().equals(landName)) ret.add(c); return ret; }
/** * getMoxen. * * @param cards a {@link java.util.ArrayList} object. * @param moxName a {@link java.lang.String} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getMoxen(ArrayList<Card> cards, String moxName) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { String name = c.getName(); if (name.equals(moxName) && !c.isCreature()) ret.add(c); } return ret; }
/** * getTokenCreatures. * * @param cards a {@link java.util.ArrayList} object. * @param tokenName a {@link java.lang.String} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getTokenCreatures(ArrayList<Card> cards, String tokenName) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { String name = c.getName(); if (c.isCreature() && c.isToken() && name.equals(tokenName)) ret.add(c); } return ret; }
/** * devModeUntapPerm. * * @since 1.0.15 */ public static void devModeUntapPerm() { CardList play = AllZoneUtil.getCardsInPlay(); Object o = GuiUtils.getChoiceOptional("Choose a permanent", play.toArray()); if (null == o) return; else { Card c = (Card) o; c.untap(); } }
/** * getEnchantedLands. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getEnchantedLands(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isLand() && c.isEnchanted()) { ret.addAll(c.getEnchantedBy()); ret.add(c); } } return ret; }
/** * When the player click a card for replacing, process and change the card. * * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (numReplaced < 2) { Card nCard = genNewCard(); nCard.addMouseListener(this); player.changeCard(player.getCards().indexOf(e.getSource()), nCard); ++numReplaced; repaint(); } }
/** devModeGenerateMana. */ public static void devModeGenerateMana() { Card dummy = new Card(); dummy.setOwner(AllZone.getHumanPlayer()); dummy.setController(AllZone.getHumanPlayer()); Ability_Mana abMana = new Ability_Mana(dummy, "0", "W U B G R 1", 10) { private static final long serialVersionUID = -2164401486331182356L; }; abMana.produceMana(); }
/** * formatCardType. * * @param card a {@link forge.Card} object. * @return a {@link java.lang.String} object. */ public static String formatCardType(Card card) { ArrayList<String> list = card.getType(); StringBuilder sb = new StringBuilder(); ArrayList<String> superTypes = new ArrayList<String>(); ArrayList<String> cardTypes = new ArrayList<String>(); ArrayList<String> subTypes = new ArrayList<String>(); for (String t : list) { if (CardUtil.isASuperType(t)) superTypes.add(t); if (CardUtil.isACardType(t)) cardTypes.add(t); if (CardUtil.isASubType(t)) subTypes.add(t); } for (String type : superTypes) { sb.append(type).append(" "); } for (String type : cardTypes) { sb.append(type).append(" "); } if (!subTypes.isEmpty()) sb.append("- "); for (String type : subTypes) { sb.append(type).append(" "); } return sb.toString(); }
/** * devModeAddCounter. * * @since 1.0.15 */ public static void devModeAddCounter() { CardList play = AllZoneUtil.getCardsInPlay(); Object o = GuiUtils.getChoiceOptional("Add counters to which card?", play.toArray()); if (null == o) return; else { Card c = (Card) o; Counters counter = GuiUtils.getChoiceOptional("Which type of counter?", Counters.values()); if (null == counter) return; else { Integer integers[] = new Integer[99]; for (int j = 0; j < 99; j++) integers[j] = Integer.valueOf(j); Integer i = GuiUtils.getChoiceOptional("How many counters?", integers); if (null == i) return; else { c.addCounterFromNonEffect(counter, i); } } } }
/** * getEquippedEnchantedCreatures. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getEquippedEnchantedCreatures(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) { if (c.isEquipped()) ret.addAll(c.getEquippedBy()); if (c.isEnchanted()) ret.addAll(c.getEnchantedBy()); ret.add(c); } } return ret; }
private void judge() { if (player.numOfSpecialCards() > dealer.numOfSpecialCards()) { player.win(); dealer.lose(); } else if (player.numOfSpecialCards() < dealer.numOfSpecialCards()) { dealer.win(); player.lose(); } else { int playerScore = 0, dealerScore = 0; for (Card card : player.getCards()) { if (!card.isSpecial()) playerScore += card.getValue(); playerScore %= 10; } for (Card card : dealer.getCards()) { if (!card.isSpecial()) dealerScore += card.getValue(); dealerScore %= 10; } if (playerScore > dealerScore) { player.win(); dealer.lose(); } else { dealer.win(); player.lose(); } } }
/** * getNonBasics. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getNonBasics(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { if (!c.isLand() && !c.getName().startsWith("Mox") && !(c instanceof ManaPool)) { ret.add(c); } else { String name = c.getName(); if (c.isEnchanted() || name.equals("Swamp") || name.equals("Bog") || name.equals("Forest") || name.equals("Grass") || name.equals("Plains") || name.equals("White Sand") || name.equals("Mountain") || name.equals("Rock") || name.equals("Island") || name.equals("Underwater") || name.equals("Badlands") || name.equals("Bayou") || name.equals("Plateau") || name.equals("Scrubland") || name.equals("Savannah") || name.equals("Taiga") || name.equals("Tropical Island") || name.equals("Tundra") || name.equals("Underground Sea") || name.equals("Volcanic Island") || name.startsWith("Mox") || c instanceof ManaPool) { // do nothing. } else { ret.add(c); } } } return ret; }
/** * When the player click the RESULT button, update the UI and judge the game, and then restart a * round or a game. * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void mouseClicked(MouseEvent e) { if (resultButton.isEnabled()) { for (Card card : dealer.getCards()) card.showFront(); betInput.setText(null); judge(); bestScore = player.getMoney() > bestScore ? player.getMoney() : bestScore; ++roundsPlayed; repaint(); if (player.getMoney() == 0) { JOptionPane.showMessageDialog(null, "All money lost, starting a new game :("); newGame(); } else { removeAll(); if (roundsPlayed == 5) { roundsPlayed = 0; JOptionPane.showMessageDialog(null, "reshuffling..."); cardUsed.clear(); } initRound(); repaint(); } } }
/** * getNonCreatureArtifacts. * * @param cards a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList<Card> getNonCreatureArtifacts(ArrayList<Card> cards) { ArrayList<Card> ret = new ArrayList<Card>(); for (Card c : cards) { String name = c.getName(); if (c.isArtifact() && !c.isCreature() && !c.isLand() && !c.isGlobalEnchantment() && !(c.isEquipment() && c.isEquipping()) && !name.equals("Mox Emerald") && !name.equals("Mox Jet") && !name.equals("Mox Pearl") && !name.equals("Mox Ruby") && !name.equals("Mox Sapphire")) ret.add(c); } return ret; }
/** * devProcessCardsForZone. * * @param data an array of {@link java.lang.String} objects. * @param player a {@link forge.Player} object. * @return a {@link forge.CardList} object. */ public static CardList devProcessCardsForZone(String[] data, Player player) { CardList cl = new CardList(); for (int i = 0; i < data.length; i++) { String cardinfo[] = data[i].trim().split("\\|"); Card c = AllZone.getCardFactory().getCard(cardinfo[0], player); if (cardinfo.length != 2) c.setCurSetCode(c.getMostRecentSet()); else c.setCurSetCode(cardinfo[1]); c.setImageFilename(CardUtil.buildFilename(c)); for (Trigger trig : c.getTriggers()) { AllZone.getTriggerHandler().registerTrigger(trig); } cl.add(c); } return cl; }
/** * getBorder. * * @param card a {@link forge.Card} object. * @return a {@link javax.swing.border.Border} object. */ public static Border getBorder(Card card) { // color info if (card == null) return BorderFactory.createEmptyBorder(2, 2, 2, 2); java.awt.Color color; ArrayList<String> list = CardUtil.getColors(card); if (card.isFaceDown()) color = Color.gray; else if (list.size() > 1) color = Color.orange; else if (list.get(0).equals(Constant.Color.Black)) color = Color.black; else if (list.get(0).equals(Constant.Color.Green)) color = new Color(0, 220, 39); else if (list.get(0).equals(Constant.Color.White)) color = Color.white; else if (list.get(0).equals(Constant.Color.Red)) color = Color.red; else if (list.get(0).equals(Constant.Color.Blue)) color = Color.blue; else if (list.get(0).equals(Constant.Color.Colorless)) color = Color.gray; else color = new Color(200, 0, 230); // If your card has a violet border, something is wrong if (color != Color.gray) { int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); int shade = 10; r -= shade; g -= shade; b -= shade; r = Math.max(0, r); g = Math.max(0, g); b = Math.max(0, b); color = new Color(r, g, b); return BorderFactory.createLineBorder(color, 2); } else return BorderFactory.createLineBorder(Color.gray, 2); }
@Override public void draw(Graphics2D g2d) { // After updating we will draw all the objects to the screen g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, windowWidth, windowHeight); g2d.setColor(Color.BLACK); Font font = new Font("Arial", Font.BOLD, 30); g2d.setFont(font); int textWidth = (int) (font.getStringBounds("You Are Now In Battle State", g2d.getFontRenderContext()) .getWidth()); g2d.drawString( "You Are Now In Battle State", windowWidth / 2 - textWidth / 2, windowHeight / 2); // Draw the battle images of the enemy and MainCharacter g2d.drawImage( mainCharacterImage, 60, 3 * windowHeight / 4 - 2 * 60, mainCharacterImage.getWidth() * 2, mainCharacterImage.getHeight() * 2, null); g2d.drawImage( enemyImage, windowWidth - 60 - enemyImage.getWidth(), 60, enemyImage.getWidth(), enemyImage.getHeight(), null); // Draw an action box at the bottom where we decide our actions on each turn g2d.setColor(Color.CYAN); g2d.fillRect(0, 3 * windowHeight / 4, windowWidth, windowHeight / 4 + 2); // Draw the hp and mp bars of the MainCharacter and the Enemy g2d.setColor(Color.BLACK); g2d.drawRect(0, 3 * windowHeight / 4, windowWidth, windowHeight / 4 + 2); Font hpFont = new Font("Arial", Font.BOLD, 15); g2d.setFont(hpFont); String text = "Health: " + String.valueOf(StartGameState.character.health) + "/" + String.valueOf(StartGameState.character.maxHealth); textWidth = (int) (hpFont.getStringBounds(text, g2d.getFontRenderContext()).getWidth()); g2d.drawString( text, 60 + mainCharacterImage.getWidth() * 2 + 45, 3 * windowHeight / 4 - 30 - 15 - 20); text = "Mana: " + String.valueOf(StartGameState.character.mana) + "/" + String.valueOf(StartGameState.character.maxMana); g2d.drawString(text, 60 + mainCharacterImage.getWidth() * 2 + 45, 3 * windowHeight / 4 - 30); text = MainCharacter.characterName; g2d.drawString( text, 60 + mainCharacterImage.getWidth() * 2 + 45, 3 * windowHeight / 4 - 30 - 2 * 15 - 2 * 20); g2d.setColor(Color.GRAY); g2d.fillRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45 - 15 - 20, 100, 15, 3, 3); g2d.fillRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45, 100, 15, 3, 3); g2d.setColor(Color.GREEN); g2d.fillRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45 - 15 - 20, (int) (((float) StartGameState.character.health / (float) StartGameState.character.maxHealth) * 100), 15, 3, 3); g2d.setColor(Color.BLUE); g2d.fillRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45, (int) (((float) StartGameState.character.mana / (float) StartGameState.character.maxMana) * 100), 15, 3, 3); g2d.setColor(Color.BLACK); g2d.drawRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45 - 15 - 20, 100, 15, 3, 3); g2d.drawRoundRect( 60 + mainCharacterImage.getWidth() * 2 + 45 + textWidth + 20, 3 * windowHeight / 4 - 45, 100, 15, 3, 3); // Enemy health and mana bars text = "Health: " + String.valueOf(enemy.health) + "/" + String.valueOf(enemy.maxHealth); textWidth = (int) (hpFont.getStringBounds(text, g2d.getFontRenderContext()).getWidth()); g2d.drawString( text, windowWidth - 60 - enemyImage.getWidth() - 45 - 100 - 20 - textWidth, 60 + 15); text = "Mana: " + String.valueOf(enemy.mana) + "/" + String.valueOf(enemy.maxMana); g2d.drawString( text, windowWidth - 60 - enemyImage.getWidth() - 45 - 100 - 20 - textWidth, 60 + 2 * 15 + 20); text = enemy.getName(); g2d.drawString( text, windowWidth - 60 - enemyImage.getWidth() - 45 - 100 - 20 - textWidth, 60 - 20); g2d.setColor(Color.GRAY); g2d.fillRoundRect(windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60, 100, 15, 3, 3); g2d.fillRoundRect( windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60 + 15 + 20, 100, 15, 3, 3); g2d.setColor(Color.GREEN); g2d.fillRoundRect( windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60, (int) (((float) enemy.health / (float) enemy.maxHealth) * 100), 15, 3, 3); g2d.setColor(Color.BLUE); g2d.fillRoundRect( windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60 + 15 + 20, (int) (((float) enemy.mana / (float) enemy.maxMana) * 100), 15, 3, 3); g2d.setColor(Color.BLACK); g2d.drawRoundRect(windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60, 100, 15, 3, 3); g2d.drawRoundRect( windowWidth - 60 - enemyImage.getWidth() - 45 - 100, 60 + 15 + 20, 100, 15, 3, 3); // Draw the player's hand and the current card int x = drawButton.getX() + drawButton.getWidth() + 40; int y = drawButton.getY() + 10; int i = 0; if (deckCount < MainCharacter.deck.size()) { g2d.drawImage(cardBack, 3 * windowWidth / 4 - 15 - cardBack.getWidth(), y, null); } if (hand.size() > 0) { int cardSpacing = cardWidth / hand.size(); for (Card card : hand.values()) { if (i != cardScroller.getCountX() - 1) { card.draw(g2d, x + i * (cardSpacing), y, 0, 0); } i++; } Card current = hand.getIndexed(cardScroller.getCountX() - 1); current.draw(g2d, x + (cardScroller.getCountX() - 1) * (cardSpacing), y - 20, 0, 0); // If it is MainCharacter turn then we draw the actions in the action box g2d.setFont(new Font("Arial", Font.BOLD, 20)); g2d.setColor(Color.BLACK); int explanationWidth = windowWidth / 4 - 25; g2d.drawString(current.getName(), 3 * windowWidth / 4 + 15, cardButton.getY()); Font explanationFont = new Font("Arial", Font.BOLD, 10); g2d.setFont(explanationFont); ArrayList<String> lines = new ArrayList<>(); // Determines width and height of only the text String dialog = current.getExplanation(); int width = (int) (explanationFont.getStringBounds(dialog, g2d.getFontRenderContext()).getWidth()); if (width > explanationWidth) { String[] split = dialog.split("\\s+"); int tempWidth = 0; int maxWidth = 0; String line = ""; for (i = 0; i < split.length; i++) { tempWidth += (int) (explanationFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); if (tempWidth > explanationWidth) { tempWidth = (int) (explanationFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); lines.add(line); line = split[i] + " "; } else { line = line + split[i] + " "; } if (tempWidth > maxWidth) { maxWidth = tempWidth; } } lines.add(line); } else { lines.add(dialog); } for (i = 0; i < lines.size(); i++) { g2d.drawString( lines.get(i), 3 * windowWidth / 4 + 15, cardButton.getY() + (i + 1) * (10 + 4)); } g2d.setFont(hpFont); String[] effects = current.getEffectStrings(); for (i = 0; i < effects.length; i++) { g2d.drawString( effects[i], 3 * windowWidth / 4 + 15, cardButton.getY() + (lines.size()) * (10 + 4) + (i + 1) * (5 + 15)); } g2d.drawString( "Mana Cost: " + String.valueOf(current.getManaCost()), 3 * windowWidth / 4 + 15, cardButton.getY() + (lines.size()) * (10 + 4) + (i + 1) * (15 + 5)); } if (drawNoMana) { g2d.setFont(new Font("Arial", Font.BOLD, 15)); g2d.drawString("You don't have", cardButton.getX(), cardButton.getY() + 15); g2d.drawString("enough mana!", cardButton.getX(), cardButton.getY() + 2 * 15 + 10); } else if (drawNoCards) { g2d.setFont(new Font("Arial", Font.BOLD, 15)); g2d.drawString("You are out of", cardButton.getX(), cardButton.getY() + 15); g2d.drawString("cards to draw!", cardButton.getX(), cardButton.getY() + 2 * 15 + 10); } else if (drawItemUsed) { g2d.setFont(new Font("Arial", Font.BOLD, 15)); g2d.drawString("You have used", cardButton.getX(), cardButton.getY() + 15); g2d.drawString( itemMenu.getLastItem().name + "!", cardButton.getX(), cardButton.getY() + 2 * 15 + 10); } else if (turn == 0 && drawParalyzed) { g2d.setFont(new Font("Arial", Font.BOLD, 15)); g2d.drawString("You cannot move,", cardButton.getX(), cardButton.getY() + 15); g2d.drawString("you're paralyzed!", cardButton.getX(), cardButton.getY() + 2 * 15 + 10); } else if (turn == 1 && drawParalyzed) { Font messageFont = new Font("Arial", Font.BOLD, 15); g2d.setFont(messageFont); text = enemy.getName() + " cannot move, they're paralyzed!"; ArrayList<String> lines = new ArrayList<>(); int width = (int) (messageFont.getStringBounds(text, g2d.getFontRenderContext()).getWidth()); if (width > cardButton.getWidth() * 2 + 40) { String[] split = text.split("\\s+"); int tempWidth = 0; int maxWidth = 0; String line = ""; for (i = 0; i < split.length; i++) { tempWidth += (int) (messageFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); if (tempWidth > cardButton.getWidth() * 2 + 40) { tempWidth = (int) (messageFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); lines.add(line); line = split[i] + " "; } else { line = line + split[i] + " "; } if (tempWidth > maxWidth) { maxWidth = tempWidth; } } lines.add(line); } else { lines.add(text); } for (i = 0; i < lines.size(); i++) { g2d.drawString(lines.get(i), cardButton.getX(), cardButton.getY() + 15 + 30 * i); } } else if (turn == 0 && turnState == 4) { g2d.setFont(new Font("Arial", Font.BOLD, 15)); g2d.drawString("You try to", cardButton.getX(), cardButton.getY() + 15); g2d.drawString("run away...", cardButton.getX(), cardButton.getY() + 2 * 15 + 10); } else if (turn == 0 && turnState == 5) { Font messageFont = new Font("Arial", Font.BOLD, 15); g2d.setFont(messageFont); if (drawMoveApplication) { text = effectMessage; } else { text = "You have used " + playedCard.getName() + " on " + enemy.getName() + "!"; } ArrayList<String> lines = new ArrayList<>(); int width = (int) (messageFont.getStringBounds(text, g2d.getFontRenderContext()).getWidth()); if (width > cardButton.getWidth() * 2 + 40) { String[] split = text.split("\\s+"); int tempWidth = 0; int maxWidth = 0; String line = ""; for (i = 0; i < split.length; i++) { tempWidth += (int) (messageFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); if (tempWidth > cardButton.getWidth() * 2 + 40) { tempWidth = (int) (messageFont .getStringBounds(split[i] + "_", g2d.getFontRenderContext()) .getWidth()); lines.add(line); line = split[i] + " "; } else { line = line + split[i] + " "; } if (tempWidth > maxWidth) { maxWidth = tempWidth; } } lines.add(line); } else { lines.add(text); } for (i = 0; i < lines.size(); i++) { g2d.drawString(lines.get(i), cardButton.getX(), cardButton.getY() + 15 + 30 * i); } } else if (turn == 0) { drawActionBox(g2d); } else if (turn == 1) { drawEnemyMessage(g2d); } else if (turn == 2) { drawVictoryMessage(g2d); } else if (turn == 3) { drawLossMessage(g2d); } }
@Override public void update(float elapsedTime, boolean[][] keyboardstate) { // All the main battle logic will go here if (turn == 0) { // If it's the MainCharacter turn we do something if (StartGameState.character.isParalyzed()) { if (drawParalyzed) { StartGameState.character.paralyzeCount -= 1; turn = 1; try { Thread.sleep(2000); } catch (InterruptedException ex) { } drawParalyzed = false; } else { drawParalyzed = true; } } else { if (turnState == 0) { if (keyboardstate[KeyEvent.VK_ENTER][1]) { if (actionScroller.getCountX() == 1 && actionScroller.getCountY() == 1) { turnState = 1; System.out.println(turnState); } else if (actionScroller.getCountX() == 1 && actionScroller.getCountY() == 2) { turnState = 2; System.out.println(turnState); } else if (actionScroller.getCountX() == 2 && actionScroller.getCountY() == 1) { turnState = 3; System.out.println(turnState); } else if (actionScroller.getCountX() == 2 && actionScroller.getCountY() == 2) { turnState = 4; System.out.println(turnState); } } else { if (!keyboardstate[KeyEvent.VK_S][0] && !keyboardstate[KeyEvent.VK_W][0] && !keyboardstate[KeyEvent.VK_A][0] && !keyboardstate[KeyEvent.VK_D][0]) { // Handle the absence of scrolling // Reset the scroller action variables actionScroller.scrollDirection = -1; actionScroller.scrollTimer = 0; } else { if (keyboardstate[KeyEvent.VK_S][0] && keyboardstate[KeyEvent.VK_W][0]) { actionScroller.scrollDirection = -1; actionScroller.scrollTimer = 0; } else if (keyboardstate[KeyEvent.VK_S][1]) { if (actionScroller.scrollDirection == 0) { // If the scroller was already scrolling down... actionScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (actionScroller.scrollTimer > actionScroller .TIMER_MAX) { // And determine if we've waited to long enough ... actionScroller.scrollTimer -= actionScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... actionScroller.scrollDown(); // And finally we scroll down. } } else { // If the scroller was not already scrolling down... actionScroller.scrollDown(); // We scroll down... actionScroller.scrollDirection = 0; // Set the scroll direction to down... actionScroller.scrollTimer = 0; // And reset the scrollTimer. } } else if (keyboardstate[KeyEvent.VK_W][1]) { if (actionScroller.scrollDirection == 3) { // If the scroller was already scrolling up... actionScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (actionScroller.scrollTimer > actionScroller .TIMER_MAX) { // And determine if we've waited to long enough ... actionScroller.scrollTimer -= actionScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... actionScroller.scrollUp(); // And finally we scroll up. } } else { // If the scroller was not already scrolling up... actionScroller.scrollUp(); // We scroll up... actionScroller.scrollDirection = 3; // Set the scroll direction to up... actionScroller.scrollTimer = 0; // And reset the scrollTimer. } } if (keyboardstate[KeyEvent.VK_A][0] && keyboardstate[KeyEvent.VK_D][0]) { actionScroller.scrollDirection = -1; actionScroller.scrollTimer = 0; } else if (keyboardstate[KeyEvent.VK_A][1]) { if (actionScroller.scrollDirection == 1) { // If the scroller was already scrolling down... actionScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (actionScroller.scrollTimer > actionScroller .TIMER_MAX) { // And determine if we've waited to long enough ... actionScroller.scrollTimer -= actionScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... actionScroller.scrollLeft(); // And finally we scroll down. } } else { // If the scroller was not already scrolling down... actionScroller.scrollLeft(); // We scroll down... actionScroller.scrollDirection = 1; // Set the scroll direction to down... actionScroller.scrollTimer = 0; // And reset the scrollTimer. } } else if (keyboardstate[KeyEvent.VK_D][1]) { if (actionScroller.scrollDirection == 2) { // If the scroller was already scrolling up... actionScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (actionScroller.scrollTimer > actionScroller .TIMER_MAX) { // And determine if we've waited to long enough ... actionScroller.scrollTimer -= actionScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... actionScroller.scrollRight(); // And finally we scroll up. } } else { // If the scroller was not already scrolling up... actionScroller.scrollRight(); // We scroll up... actionScroller.scrollDirection = 2; // Set the scroll direction to up... actionScroller.scrollTimer = 0; // And reset the scrollTimer. } } } } } else if (turnState == 1) { if (drawNoMana) { try { Thread.sleep(2000); } catch (InterruptedException ex) { } drawNoMana = false; } else { if (keyboardstate[KeyEvent.VK_BACK_SPACE][1]) { turnState = 0; } else if (keyboardstate[KeyEvent.VK_ENTER][1]) { playedCard = hand.getIndexed(cardScroller.getCountX() - 1); if (StartGameState.character.mana < playedCard.getManaCost()) { drawNoMana = true; } else { turnState = 5; hand.remove(hand.getIndexedKey(cardScroller.getCountX() - 1)); cardScroller.setMenuCountX(hand.size()); cardScroller.setCountX(cardScroller.getCountX() - 1); if (cardScroller.getCountX() <= 0) { cardScroller.setCountX(1); } if (hand.size() > 0) { cardScroller.setMenuSpacingX(cardWidth / hand.size()); } } } else { if (!keyboardstate[KeyEvent.VK_S][0] && !keyboardstate[KeyEvent.VK_W][0] && !keyboardstate[KeyEvent.VK_A][0] && !keyboardstate[KeyEvent.VK_D][0]) { // Handle the absence of scrolling // Reset the scroller action variables cardScroller.scrollDirection = -1; cardScroller.scrollTimer = 0; } else { if (keyboardstate[KeyEvent.VK_S][0] && keyboardstate[KeyEvent.VK_W][0]) { cardScroller.scrollDirection = -1; cardScroller.scrollTimer = 0; } else if (keyboardstate[KeyEvent.VK_S][1]) { if (cardScroller.scrollDirection == 0) { // If the scroller was already scrolling down... cardScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (cardScroller.scrollTimer > cardScroller .TIMER_MAX) { // And determine if we've waited to long enough ... cardScroller.scrollTimer -= cardScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... cardScroller.scrollDown(); // And finally we scroll down. } } else { // If the scroller was not already scrolling down... cardScroller.scrollDown(); // We scroll down... cardScroller.scrollDirection = 0; // Set the scroll direction to down... cardScroller.scrollTimer = 0; // And reset the scrollTimer. } } else if (keyboardstate[KeyEvent.VK_W][1]) { if (cardScroller.scrollDirection == 3) { // If the scroller was already scrolling up... cardScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (cardScroller.scrollTimer > cardScroller .TIMER_MAX) { // And determine if we've waited to long enough ... cardScroller.scrollTimer -= cardScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... cardScroller.scrollUp(); // And finally we scroll up. } } else { // If the scroller was not already scrolling up... cardScroller.scrollUp(); // We scroll up... cardScroller.scrollDirection = 3; // Set the scroll direction to up... cardScroller.scrollTimer = 0; // And reset the scrollTimer. } } if (keyboardstate[KeyEvent.VK_A][0] && keyboardstate[KeyEvent.VK_D][0]) { cardScroller.scrollDirection = -1; cardScroller.scrollTimer = 0; } else if (keyboardstate[KeyEvent.VK_A][1]) { if (cardScroller.scrollDirection == 1) { // If the scroller was already scrolling down... cardScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (cardScroller.scrollTimer > cardScroller .TIMER_MAX) { // And determine if we've waited to long enough ... cardScroller.scrollTimer -= cardScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... cardScroller.scrollLeft(); // And finally we scroll down. } } else { // If the scroller was not already scrolling down... cardScroller.scrollLeft(); // We scroll down... cardScroller.scrollDirection = 1; // Set the scroll direction to down... cardScroller.scrollTimer = 0; // And reset the scrollTimer. } } else if (keyboardstate[KeyEvent.VK_D][1]) { if (cardScroller.scrollDirection == 2) { // If the scroller was already scrolling up... cardScroller.scrollTimer += elapsedTime; // We add the elapsed time to the scroll timer... if (cardScroller.scrollTimer > cardScroller .TIMER_MAX) { // And determine if we've waited to long enough ... cardScroller.scrollTimer -= cardScroller .TIMER_MAX; // To justify a scroll. We reset the scrollTimer... cardScroller.scrollRight(); // And finally we scroll up. } } else { // If the scroller was not already scrolling up... cardScroller.scrollRight(); // We scroll up... cardScroller.scrollDirection = 2; // Set the scroll direction to up... cardScroller.scrollTimer = 0; // And reset the scrollTimer. } } } } } } else if (turnState == 2) { if (shouldWait) { if (itemMenu.isActive()) { itemMenu.update(elapsedTime, keyboardstate); if (keyboardstate[KeyEvent.VK_ENTER][1]) { itemMenu.setActive(false); drawItemUsed = true; } } else { shouldWait = false; drawItemUsed = false; try { // Waits a little on the enemy turn, this is just for testing and will be removed // when AI is written Thread.sleep(1500); } catch (InterruptedException ex) { } turnState = 0; turn = 1; } } else { itemMenu.setActive(true); if (keyboardstate[KeyEvent.VK_BACK_SPACE][1]) { turnState = 0; itemMenu.setActive(false); } else { itemMenu.update(elapsedTime, keyboardstate); if (keyboardstate[KeyEvent.VK_ENTER][1]) { if (itemMenu.state == 1 && itemMenu.error == false) { shouldWait = true; } } } } } else if (turnState == 3) { if (shouldWait) { try { // Waits a little on the enemy turn, this is just for testing and will be removed when // AI is written Thread.sleep(2000); } catch (InterruptedException ex) { } drawNoCards = false; shouldWait = false; turnState = 0; } else { if (keyboardstate[KeyEvent.VK_BACK_SPACE][1]) { turnState = 0; } else if (keyboardstate[KeyEvent.VK_ENTER][1]) { if (deckCount >= MainCharacter.deck.size()) { drawNoCards = true; shouldWait = true; } else { hand.put( hand.getIndexedKey(hand.size() - 1) + 1, MainCharacter.deck.get(deckCount)); cardScroller.setMenuCountX(hand.size()); cardScroller.setMenuSpacingX(cardWidth / hand.size()); deckCount++; turn = 1; turnState = 0; } } } } else if (turnState == 4) { if (keyboardstate[KeyEvent.VK_BACK_SPACE][1]) { turnState = 0; } } else if (turnState == 5) { try { if (drawMoveApplication) { Thread.sleep(1800); if (enemy.health > 0) { turn = 1; turnState = 0; } else { turn = 2; } drawMoveApplication = false; } else { Thread.sleep(1800); effectMessage = playedCard.applyEffect(StartGameState.character, enemy); drawMoveApplication = true; } } catch (InterruptedException ex) { } } } } else if (turn == 1) { // If it's the Enemy's turn we can't do anything, and the AI decides what to do try { if (enemy.isParalyzed()) { if (drawParalyzed) { enemy.paralyzeCount -= 1; turn = 0; try { Thread.sleep(2000); } catch (InterruptedException ex) { } drawParalyzed = false; } else { drawParalyzed = true; } } else { // Waits a little on the enemy turn, this is just for testing and will be removed when AI // is written if (enemyMoveChosen) { Thread.sleep(1800); if (drawMoveApplication) { turn = 0; enemyMoveChosen = false; drawMoveApplication = false; } else { drawMoveApplication = true; } } else { if (enemy.getClass().equals(Creature.class)) { Creature creature = (Creature) enemy; int moveCount = creature.battleMoves.length; Random rand = new Random(); double r = rand.nextDouble(); int i = 1; while (r > (double) i / moveCount) { i++; } lastEnemyMove = MoveCache.getMove(creature.battleMoves[i - 1]); effectMessage = lastEnemyMove.applyEffect(creature, StartGameState.character); enemyMoveChosen = true; } Thread.sleep(1500); } } } catch (InterruptedException ex) { } } else if (turn == 2) { try { // Waits a little when the battle is won Thread.sleep(2000); } catch (InterruptedException ex) { } endEvent(); } else if (turn == 3) { try { // Waits a little when the battle is lost Thread.sleep(2000); } catch (InterruptedException ex) { } endEvent(); } }
/** * isStackable. * * @param c a {@link forge.Card} object. * @return a boolean. */ public static boolean isStackable(Card c) { /*String name = c.getName(); if( name.equals("Swamp") || name.equals("Bog") || name.equals("Forest") || name.equals("Grass") || name.equals("Plains") || name.equals("White Sand") || name.equals("Mountain") || name.equals("Rock") || name.equals("Island") || name.equals("Underwater")) { return true; } */ if (c.isLand() || (c.getName().startsWith("Mox") && !c.getName().equals("Mox Diamond")) || (c.isLand() && c.isEnchanted()) || (c.isAura() && c.isEnchanting()) || (c.isToken() && CardFactoryUtil.multipleControlled(c)) || (c.isCreature() && (c.isEquipped() || c.isEnchanted())) || (c.isEquipment() && c.isEquipping()) || (c.isEnchantment()) || (c instanceof ManaPool && c.isSnow())) return true; return false; }
/** * setupPlayZone. * * @param p a {@link arcane.ui.PlayArea} object. * @param c an array of {@link forge.Card} objects. */ public static void setupPlayZone(PlayArea p, Card c[]) { List<Card> tmp, diff; tmp = new ArrayList<Card>(); for (arcane.ui.CardPanel cpa : p.cardPanels) tmp.add(cpa.gameCard); diff = new ArrayList<Card>(tmp); diff.removeAll(Arrays.asList(c)); if (diff.size() == p.cardPanels.size()) p.clear(); else { for (Card card : diff) { p.removeCardPanel(p.getCardPanel(card.getUniqueNumber())); } } diff = new ArrayList<Card>(Arrays.asList(c)); diff.removeAll(tmp); arcane.ui.CardPanel toPanel = null; for (Card card : diff) { toPanel = p.addCard(card); Animation.moveCard(toPanel); } for (Card card : c) { toPanel = p.getCardPanel(card.getUniqueNumber()); if (card.isTapped()) { toPanel.tapped = true; toPanel.tappedAngle = arcane.ui.CardPanel.TAPPED_ANGLE; } else { toPanel.tapped = false; toPanel.tappedAngle = 0; } toPanel.attachedPanels.clear(); if (card.isEnchanted()) { ArrayList<Card> enchants = card.getEnchantedBy(); for (Card e : enchants) { arcane.ui.CardPanel cardE = p.getCardPanel(e.getUniqueNumber()); if (cardE != null) toPanel.attachedPanels.add(cardE); } } if (card.isEquipped()) { ArrayList<Card> enchants = card.getEquippedBy(); for (Card e : enchants) { arcane.ui.CardPanel cardE = p.getCardPanel(e.getUniqueNumber()); if (cardE != null) toPanel.attachedPanels.add(cardE); } } if (card.isEnchanting()) { toPanel.attachedToPanel = p.getCardPanel(card.getEnchanting().get(0).getUniqueNumber()); } else if (card.isEquipping()) { toPanel.attachedToPanel = p.getCardPanel(card.getEquipping().get(0).getUniqueNumber()); } else toPanel.attachedToPanel = null; toPanel.setCard(toPanel.gameCard); } p.invalidate(); p.repaint(); }
/** devSetupGameState. */ public static void devSetupGameState() { String t_humanLife = "-1"; String t_computerLife = "-1"; String t_humanSetupCardsInPlay = "NONE"; String t_computerSetupCardsInPlay = "NONE"; String t_humanSetupCardsInHand = "NONE"; String t_computerSetupCardsInHand = "NONE"; String t_humanSetupGraveyard = "NONE"; String t_computerSetupGraveyard = "NONE"; String t_humanSetupLibrary = "NONE"; String t_computerSetupLibrary = "NONE"; String t_humanSetupExile = "NONE"; String t_computerSetupExile = "NONE"; String t_changePlayer = "NONE"; String t_changePhase = "NONE"; String wd = "."; JFileChooser fc = new JFileChooser(wd); int rc = fc.showDialog(null, "Select Game State File"); if (rc != JFileChooser.APPROVE_OPTION) return; try { FileInputStream fstream = new FileInputStream(fc.getSelectedFile().getAbsolutePath()); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String temp = ""; while ((temp = br.readLine()) != null) { String[] temp_data = temp.split("="); if (temp_data.length < 2) continue; if (temp_data[0].toCharArray()[0] == '#') continue; String categoryName = temp_data[0]; String categoryValue = temp_data[1]; if (categoryName.toLowerCase().equals("humanlife")) t_humanLife = categoryValue; else if (categoryName.toLowerCase().equals("ailife")) t_computerLife = categoryValue; else if (categoryName.toLowerCase().equals("humancardsinplay")) t_humanSetupCardsInPlay = categoryValue; else if (categoryName.toLowerCase().equals("aicardsinplay")) t_computerSetupCardsInPlay = categoryValue; else if (categoryName.toLowerCase().equals("humancardsinhand")) t_humanSetupCardsInHand = categoryValue; else if (categoryName.toLowerCase().equals("aicardsinhand")) t_computerSetupCardsInHand = categoryValue; else if (categoryName.toLowerCase().equals("humancardsingraveyard")) t_humanSetupGraveyard = categoryValue; else if (categoryName.toLowerCase().equals("aicardsingraveyard")) t_computerSetupGraveyard = categoryValue; else if (categoryName.toLowerCase().equals("humancardsinlibrary")) t_humanSetupLibrary = categoryValue; else if (categoryName.toLowerCase().equals("aicardsinlibrary")) t_computerSetupLibrary = categoryValue; else if (categoryName.toLowerCase().equals("humancardsinexile")) t_humanSetupExile = categoryValue; else if (categoryName.toLowerCase().equals("aicardsinexile")) t_computerSetupExile = categoryValue; else if (categoryName.toLowerCase().equals("activeplayer")) t_changePlayer = categoryValue; else if (categoryName.toLowerCase().equals("activephase")) t_changePhase = categoryValue; } in.close(); } catch (FileNotFoundException fnfe) { JOptionPane.showMessageDialog( null, "File not found: " + fc.getSelectedFile().getAbsolutePath()); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error loading battle setup file!"); return; } int setHumanLife = Integer.parseInt(t_humanLife); int setComputerLife = Integer.parseInt(t_computerLife); String humanSetupCardsInPlay[] = t_humanSetupCardsInPlay.split(";"); String computerSetupCardsInPlay[] = t_computerSetupCardsInPlay.split(";"); String humanSetupCardsInHand[] = t_humanSetupCardsInHand.split(";"); String computerSetupCardsInHand[] = t_computerSetupCardsInHand.split(";"); String humanSetupGraveyard[] = t_humanSetupGraveyard.split(";"); String computerSetupGraveyard[] = t_computerSetupGraveyard.split(";"); String humanSetupLibrary[] = t_humanSetupLibrary.split(";"); String computerSetupLibrary[] = t_computerSetupLibrary.split(";"); String humanSetupExile[] = t_humanSetupExile.split(";"); String computerSetupExile[] = t_computerSetupExile.split(";"); CardList humanDevSetup = new CardList(); CardList computerDevSetup = new CardList(); CardList humanDevHandSetup = new CardList(); CardList computerDevHandSetup = new CardList(); CardList humanDevGraveyardSetup = new CardList(); CardList computerDevGraveyardSetup = new CardList(); CardList humanDevLibrarySetup = new CardList(); CardList computerDevLibrarySetup = new CardList(); CardList humanDevExileSetup = new CardList(); CardList computerDevExileSetup = new CardList(); if (!t_changePlayer.trim().toLowerCase().equals("none")) { if (t_changePlayer.trim().toLowerCase().equals("human")) { AllZone.getPhase().setPlayerTurn(AllZone.getHumanPlayer()); } if (t_changePlayer.trim().toLowerCase().equals("ai")) { AllZone.getPhase().setPlayerTurn(AllZone.getComputerPlayer()); } } if (!t_changePhase.trim().toLowerCase().equals("none")) { AllZone.getPhase().setDevPhaseState(t_changePhase); } if (!t_humanSetupCardsInPlay.trim().toLowerCase().equals("none")) humanDevSetup = devProcessCardsForZone(humanSetupCardsInPlay, AllZone.getHumanPlayer()); if (!t_humanSetupCardsInHand.trim().toLowerCase().equals("none")) humanDevHandSetup = devProcessCardsForZone(humanSetupCardsInHand, AllZone.getHumanPlayer()); if (!t_computerSetupCardsInPlay.trim().toLowerCase().equals("none")) computerDevSetup = devProcessCardsForZone(computerSetupCardsInPlay, AllZone.getComputerPlayer()); if (!t_computerSetupCardsInHand.trim().toLowerCase().equals("none")) computerDevHandSetup = devProcessCardsForZone(computerSetupCardsInHand, AllZone.getComputerPlayer()); if (!t_computerSetupGraveyard.trim().toLowerCase().equals("none")) computerDevGraveyardSetup = devProcessCardsForZone(computerSetupGraveyard, AllZone.getComputerPlayer()); if (!t_humanSetupGraveyard.trim().toLowerCase().equals("none")) humanDevGraveyardSetup = devProcessCardsForZone(humanSetupGraveyard, AllZone.getHumanPlayer()); if (!t_humanSetupLibrary.trim().toLowerCase().equals("none")) humanDevLibrarySetup = devProcessCardsForZone(humanSetupLibrary, AllZone.getHumanPlayer()); if (!t_computerSetupLibrary.trim().toLowerCase().equals("none")) computerDevLibrarySetup = devProcessCardsForZone(computerSetupLibrary, AllZone.getComputerPlayer()); if (!t_humanSetupExile.trim().toLowerCase().equals("none")) humanDevExileSetup = devProcessCardsForZone(humanSetupExile, AllZone.getHumanPlayer()); if (!t_computerSetupExile.trim().toLowerCase().equals("none")) computerDevExileSetup = devProcessCardsForZone(computerSetupExile, AllZone.getComputerPlayer()); AllZone.getTriggerHandler().suppressMode("ChangesZone"); for (Card c : humanDevSetup) { AllZone.getHumanHand().add(c); AllZone.getGameAction().moveToPlay(c); c.setSickness(false); } for (Card c : computerDevSetup) { AllZone.getComputerHand().add(c); AllZone.getGameAction().moveToPlay(c); c.setSickness(false); } if (computerDevGraveyardSetup.size() > 0) AllZone.getComputerGraveyard().setCards(computerDevGraveyardSetup.toArray()); if (humanDevGraveyardSetup.size() > 0) AllZone.getHumanGraveyard().setCards(humanDevGraveyardSetup.toArray()); if (computerDevHandSetup.size() > 0) AllZone.getComputerHand().setCards(computerDevHandSetup.toArray()); if (humanDevHandSetup.size() > 0) AllZone.getHumanHand().setCards(humanDevHandSetup.toArray()); if (humanDevLibrarySetup.size() > 0) AllZone.getHumanLibrary().setCards(humanDevLibrarySetup.toArray()); if (computerDevLibrarySetup.size() > 0) AllZone.getComputerLibrary().setCards(computerDevLibrarySetup.toArray()); if (humanDevExileSetup.size() > 0) AllZone.getHumanExile().setCards(humanDevExileSetup.toArray()); if (computerDevExileSetup.size() > 0) AllZone.getComputerExile().setCards(computerDevExileSetup.toArray()); AllZone.getTriggerHandler().clearSuppression("ChangesZone"); if (setComputerLife > 0) AllZone.getComputerPlayer().setLife(setComputerLife, null); if (setHumanLife > 0) AllZone.getHumanPlayer().setLife(setHumanLife, null); AllZone.getGameAction().checkStateEffects(); AllZone.getPhase().updateObservers(); AllZone.getHumanExile().updateObservers(); AllZone.getComputerExile().updateObservers(); AllZone.getHumanHand().updateObservers(); AllZone.getComputerHand().updateObservers(); AllZone.getHumanGraveyard().updateObservers(); AllZone.getComputerGraveyard().updateObservers(); AllZone.getHumanBattlefield().updateObservers(); AllZone.getComputerBattlefield().updateObservers(); AllZone.getHumanLibrary().updateObservers(); AllZone.getComputerLibrary().updateObservers(); }
/** * setupPanel. * * @param p a {@link javax.swing.JPanel} object. * @param list a {@link java.util.ArrayList} object. * @param stack a boolean. */ private static void setupPanel(JPanel p, ArrayList<Card> list, boolean stack) { int maxY = 0; int maxX = 0; // remove all local enchantments Card c; /* for(int i = 0; i < list.size(); i++) { c = (Card)list.get(i); if(c.isLocalEnchantment()) list.remove(i); } //add local enchantments to the permanents //put local enchantments "next to" the permanent they are enchanting //the inner for loop is backward so permanents with more than one local enchantments are in the right order Card ca[]; for(int i = 0; i < list.size(); i++) { c = (Card)list.get(i); if(c.hasAttachedCards()) { ca = c.getAttachedCards(); for(int inner = ca.length - 1; 0 <= inner; inner--) list.add(i + 1, ca[inner]); } } */ if (stack) { // add all Cards in list to the GUI, add arrows to Local Enchantments ArrayList<Card> manaPools = getManaPools(list); ArrayList<Card> enchantedLands = getEnchantedLands(list); ArrayList<Card> basicBlues = getBasics(list, Constant.Color.Blue); ArrayList<Card> basicReds = getBasics(list, Constant.Color.Red); ArrayList<Card> basicBlacks = getBasics(list, Constant.Color.Black); ArrayList<Card> basicGreens = getBasics(list, Constant.Color.Green); ArrayList<Card> basicWhites = getBasics(list, Constant.Color.White); ArrayList<Card> badlands = getNonBasicLand(list, "Badlands"); ArrayList<Card> bayou = getNonBasicLand(list, "Bayou"); ArrayList<Card> plateau = getNonBasicLand(list, "Plateau"); ArrayList<Card> scrubland = getNonBasicLand(list, "Scrubland"); ArrayList<Card> savannah = getNonBasicLand(list, "Savannah"); ArrayList<Card> taiga = getNonBasicLand(list, "Taiga"); ArrayList<Card> tropicalIsland = getNonBasicLand(list, "Tropical Island"); ArrayList<Card> tundra = getNonBasicLand(list, "Tundra"); ArrayList<Card> undergroundSea = getNonBasicLand(list, "Underground Sea"); ArrayList<Card> volcanicIsland = getNonBasicLand(list, "Volcanic Island"); ArrayList<Card> nonBasics = getNonBasics(list); ArrayList<Card> moxEmerald = getMoxen(list, "Mox Emerald"); ArrayList<Card> moxJet = getMoxen(list, "Mox Jet"); ArrayList<Card> moxPearl = getMoxen(list, "Mox Pearl"); ArrayList<Card> moxRuby = getMoxen(list, "Mox Ruby"); ArrayList<Card> moxSapphire = getMoxen(list, "Mox Sapphire"); // ArrayList<Card> moxDiamond = getMoxen(list, "Mox Diamond"); list = new ArrayList<Card>(); list.addAll(manaPools); list.addAll(enchantedLands); list.addAll(basicBlues); list.addAll(basicReds); list.addAll(basicBlacks); list.addAll(basicGreens); list.addAll(basicWhites); list.addAll(badlands); list.addAll(bayou); list.addAll(plateau); list.addAll(scrubland); list.addAll(savannah); list.addAll(taiga); list.addAll(tropicalIsland); list.addAll(tundra); list.addAll(undergroundSea); list.addAll(volcanicIsland); list.addAll(nonBasics); list.addAll(moxEmerald); list.addAll(moxJet); list.addAll(moxPearl); list.addAll(moxRuby); list.addAll(moxSapphire); // list.addAll(moxDiamond); int atInStack = 0; int marginX = 5; int marginY = 5; int x = marginX; int cardOffset = Constant.Runtime.stackOffset[0]; String color = ""; ArrayList<JPanel> cards = new ArrayList<JPanel>(); ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>(); boolean nextEnchanted = false; Card prevCard = null; int nextXIfNotStacked = 0; for (int i = 0; i < list.size(); i++) { JPanel addPanel; c = list.get(i); addPanel = new CardPanel(c); boolean startANewStack = false; if (!isStackable(c)) { startANewStack = true; } else { String newColor = c.getName(); // CardUtil.getColor(c); if (!newColor.equals(color)) { startANewStack = true; color = newColor; } } if (i == 0) { startANewStack = false; } if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) { startANewStack = true; } if (c.isAura() && c.isEnchanting() && !nextEnchanted) startANewStack = false; else if (c.isAura() && c.isEnchanting()) { startANewStack = true; nextEnchanted = false; } if (c.isLand() && c.isEnchanted()) { startANewStack = false; nextEnchanted = true; } // very hacky, but this is to ensure enchantment stacking occurs correctly when a land is // enchanted, and there are more lands of that same name else if ((prevCard != null && c.isLand() && prevCard.isLand() && prevCard.isEnchanted() && prevCard.getName().equals(c.getName()))) startANewStack = true; else if (prevCard != null && c.isLand() && prevCard.isLand() && !prevCard.getName().equals(c.getName())) startANewStack = true; /* if (c.getName().equals("Squirrel Nest")) { startANewStack = true; System.out.println("startANewStack: " + startANewStack); } */ if (c.isAura() && c.isEnchanting() && prevCard != null && prevCard instanceof ManaPool) startANewStack = true; if (c instanceof ManaPool && prevCard instanceof ManaPool && prevCard.isSnow()) startANewStack = false; if (startANewStack) { setupConnectedCards(connectedCards); connectedCards.clear(); // Fixed distance if last was a stack, looks a bit nicer if (atInStack > 1) { x += Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height) + marginX; } else { x = nextXIfNotStacked; } atInStack = 0; } else { if (i != 0) { x += cardOffset; } } nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width; int xLoc = x; int yLoc = marginY; yLoc += atInStack * cardOffset; addPanel.setLocation(new Point(xLoc, yLoc)); addPanel.setSize(addPanel.getPreferredSize()); cards.add(addPanel); connectedCards.add((CardPanel) addPanel); atInStack++; prevCard = c; } setupConnectedCards(connectedCards); connectedCards.clear(); for (int i = cards.size() - 1; i >= 0; i--) { JPanel card = cards.get(i); // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX); maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY); p.add(card); } maxX = nextXIfNotStacked; // System.out.println("x:" + maxX + ", y:" + maxY); if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) { // p.setSize(new Dimension(maxX, maxY)); p.setPreferredSize(new Dimension(maxX, maxY)); } } else { // add all Cards in list to the GUI, add arrows to Local Enchantments JPanel addPanel; for (int i = 0; i < list.size(); i++) { c = list.get(i); /*if(c.isLocalEnchantment()) addPanel = getCardPanel(c, "<< " +c.getName()); else addPanel = getCardPanel(c); */ addPanel = new CardPanel(c); p.add(addPanel); } } } // setupPanel()
/** * setupNoLandPermPanel. * * @param p a {@link javax.swing.JPanel} object. * @param list a {@link java.util.ArrayList} object. * @param stack a boolean. */ private static void setupNoLandPermPanel(JPanel p, ArrayList<Card> list, boolean stack) { int maxY = 0; int maxX = 0; Card c; if (stack) { // add all Cards in list to the GUI, add arrows to Local Enchantments ArrayList<Card> planeswalkers = getPlaneswalkers(list); ArrayList<Card> equippedEnchantedCreatures = getEquippedEnchantedCreatures( list); // this will also fetch the equipment and/or enchantment ArrayList<Card> nonTokenCreatures = getNonTokenCreatures(list); ArrayList<Card> tokenCreatures = getTokenCreatures(list); // sort tokenCreatures by name (TODO: fix the warning message somehow) Collections.sort( tokenCreatures, new Comparator<Card>() { public int compare(Card c1, Card c2) { return c1.getName().compareTo(c2.getName()); } }); ArrayList<Card> artifacts = getNonCreatureArtifacts(list); ArrayList<Card> enchantments = getGlobalEnchantments(list); // ArrayList<Card> nonBasics = getNonBasics(list); list = new ArrayList<Card>(); list.addAll(planeswalkers); list.addAll(equippedEnchantedCreatures); list.addAll(nonTokenCreatures); list.addAll(tokenCreatures); list.addAll(artifacts); list.addAll(enchantments); int atInStack = 0; int marginX = 5; int marginY = 5; int x = marginX; int cardOffset = Constant.Runtime.stackOffset[0]; String color = ""; ArrayList<JPanel> cards = new ArrayList<JPanel>(); ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>(); boolean nextEquippedEnchanted = false; int nextXIfNotStacked = 0; Card prevCard = null; for (int i = 0; i < list.size(); i++) { JPanel addPanel; c = list.get(i); addPanel = new CardPanel(c); boolean startANewStack = false; if (!isStackable(c)) { startANewStack = true; } else { String newColor = c.getName(); // CardUtil.getColor(c); if (!newColor.equals(color)) { startANewStack = true; color = newColor; } } if (i == 0) { startANewStack = false; } if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) { startANewStack = true; } if ((c.isEquipment() || c.isAura()) && (c.isEquipping() || c.isEnchanting()) && !nextEquippedEnchanted) startANewStack = false; else if ((c.isEquipment() || c.isAura()) && (c.isEquipping() || c.isEnchanting())) { startANewStack = true; nextEquippedEnchanted = false; } if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) { startANewStack = false; nextEquippedEnchanted = true; } // very hacky, but this is to ensure equipment stacking occurs correctly when a token is // equipped/enchanted, and there are more tokens of that same name else if ((prevCard != null && c.isCreature() && prevCard.isCreature() && (prevCard.isEquipped() || prevCard.isEnchanted()) && prevCard.getName().equals(c.getName()))) startANewStack = true; else if (prevCard != null && c.isCreature() && prevCard.isCreature() && !prevCard.getName().equals(c.getName())) startANewStack = true; if (((c.isAura() && c.isEnchanting()) || (c.isEquipment() && c.isEquipping())) && prevCard != null && prevCard.isPlaneswalker()) startANewStack = true; if (startANewStack) { setupConnectedCards(connectedCards); connectedCards.clear(); // Fixed distance if last was a stack, looks a bit nicer if (atInStack > 1) { x += Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height) + marginX; } else { x = nextXIfNotStacked; } atInStack = 0; } else { if (i != 0) { x += cardOffset; } } nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width; int xLoc = x; int yLoc = marginY; yLoc += atInStack * cardOffset; addPanel.setLocation(new Point(xLoc, yLoc)); addPanel.setSize(addPanel.getPreferredSize()); cards.add(addPanel); connectedCards.add((CardPanel) addPanel); atInStack++; prevCard = c; } setupConnectedCards(connectedCards); connectedCards.clear(); for (int i = cards.size() - 1; i >= 0; i--) { JPanel card = cards.get(i); // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX); maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY); p.add(card); } maxX = nextXIfNotStacked; if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) { p.setPreferredSize(new Dimension(maxX, maxY)); } } else { JPanel addPanel; for (int i = 0; i < list.size(); i++) { c = list.get(i); addPanel = new CardPanel(c); p.add(addPanel); } } } // setupPanel()