mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Added random colors to deck generator. Fixed Issue 267.
This commit is contained in:
parent
f405c7dd0d
commit
446c1517cf
2 changed files with 39 additions and 4 deletions
|
|
@ -14,13 +14,12 @@ import mage.utils.CardUtil;
|
|||
import mage.utils.DeckBuilder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Generates random card pool and builds a deck.
|
||||
|
|
@ -43,6 +42,8 @@ public class DeckGenerator {
|
|||
private static Deck deck = new Deck();
|
||||
private static final int ADDITIONAL_CARDS_FOR_3_COLOR_DECKS = 20;
|
||||
|
||||
private static String colors = "GWUBR";
|
||||
|
||||
/**
|
||||
* Opens color chooser dialog. Generates deck.
|
||||
* Saves generated deck and use it as selected deck to play.
|
||||
|
|
@ -59,6 +60,10 @@ public class DeckGenerator {
|
|||
final ColorsChooser colorsChooser = new ColorsChooser(chosen);
|
||||
p0.add(colorsChooser);
|
||||
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
JLabel text2 = new JLabel("(X - random color)");
|
||||
p0.add(text2);
|
||||
|
||||
final JButton btnGenerate = new JButton("Ok");
|
||||
btnGenerate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
@ -106,6 +111,11 @@ public class DeckGenerator {
|
|||
protected static void buildDeck() {
|
||||
List<ColoredManaSymbol> allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
selectedColors = selectedColors.toUpperCase();
|
||||
|
||||
if (selectedColors.contains("X")) {
|
||||
selectedColors = getRandomColors(selectedColors);
|
||||
}
|
||||
|
||||
for (int i = 0; i < selectedColors.length(); i++) {
|
||||
char c = selectedColors.charAt(i);
|
||||
allowedColors.add(ColoredManaSymbol.lookup(c));
|
||||
|
|
@ -132,6 +142,28 @@ public class DeckGenerator {
|
|||
});
|
||||
}
|
||||
|
||||
private static String getRandomColors(String _selectedColors) {
|
||||
StringBuilder generatedColors = new StringBuilder();
|
||||
Set<String> colors = new HashSet<String>();
|
||||
for (int i = 0; i < _selectedColors.length(); i++) {
|
||||
String color = getRandomColor() + "";
|
||||
int retry = 100;
|
||||
while (colors.contains(color)) {
|
||||
color = getRandomColor() + "";
|
||||
retry--;
|
||||
if (retry <= 0) break;
|
||||
}
|
||||
generatedColors.append(color);
|
||||
colors.add(color);
|
||||
}
|
||||
return generatedColors.toString();
|
||||
}
|
||||
|
||||
private static char getRandomColor() {
|
||||
Random r = new Random();
|
||||
return colors.charAt(r.nextInt(colors.length()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates card pool of cardsCount cards that have manacost of allowed colors.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
|
|||
model.addElement("b");
|
||||
model.addElement("g");
|
||||
model.addElement("w");
|
||||
model.addElement("x");
|
||||
|
||||
model.addElement("bu");
|
||||
model.addElement("bg");
|
||||
|
|
@ -44,6 +45,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
|
|||
model.addElement("gr");
|
||||
model.addElement("gw");
|
||||
model.addElement("rw");
|
||||
model.addElement("xx");
|
||||
|
||||
model.addElement("bur");
|
||||
model.addElement("buw");
|
||||
|
|
@ -55,6 +57,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
|
|||
model.addElement("wug");
|
||||
model.addElement("wrg");
|
||||
model.addElement("rgu");
|
||||
model.addElement("xxx");
|
||||
|
||||
setModel(model);
|
||||
setSelectedItem(colors);
|
||||
|
|
@ -97,7 +100,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
|
|||
dx += 13;
|
||||
}
|
||||
} else {
|
||||
String s = value.replace("B", "{B}").replace("R", "{R}").replace("G", "{G}").replace("W", "{W}").replace("U", "{U}");
|
||||
String s = value.replace("B", "{B}").replace("R", "{R}").replace("G", "{G}").replace("W", "{W}").replace("U", "{U}").replace("X", "{X}");
|
||||
panel.add(new JLabel(s));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue