dimanche 19 septembre 2021

How do I make my packs class give me cards?

I have made my packs class and it works fine (meaning it has no exceptions) but it gives me a different result this is my code for packs:

 public class Packs {
    static Deck d = new Deck();
    Packs(ArrayList<Cards> cards) throws IOException{
    Deck.getFullCollection();
    }
    public static void main(String[] args) {
        Random PO = new Random();
        for(int counter = 1; counter<=7;  counter++) {
        int number = 1+PO.nextInt(10000000);
        if(number < 41650) {
            System.out.println (p.Cards.Rarity.Shadow);
        } else if (number < 208616) {
            System.out.println (p.Cards.Rarity.Epic);
        } else if (number < 1041949) {  
            System.out.println (p.Cards.Rarity.Uncommon);
        } else if (number < 10000001) {
            System.out.println (p.Cards.Rarity.Common);
        }
    }
        }
};'

The code above gives me 7 messages saying "common" "uncommon" "epic" and\or "shadow" depending on how lucky I am, when instead I want it to give me the cards below at random:

    public class Deck {
    protected static ArrayList<Cards> cards;
    public Deck() {
        cards = new ArrayList<Cards>();
    }
    public int getMana(int Mana) {
        return Mana;
    }   
        public static void getFullCollection() throws IOException {
            Cards Shuriken = new Attacks(3, 2, Effects.Return, Cards.Classs.Ninja, Cards.Rarity.Common, ImageIO.read(new File("Shuriken.png")));
            System.out.println(Shuriken.toString());
            Deck.cards.add(Shuriken);
            Cards Tricks = new Attacks(8, 7, Effects.Return, Cards.Classs.Ninja, Cards.Rarity.Epic, ImageIO.read(new File("Shuriken.png")));
            System.out.println(Tricks.toString());
            Deck.cards.add(Tricks);
               Cards Strike = new Attacks(4, 5, Effects.Return, Cards.Classs.Ninja, Cards.Rarity.Shadow, ImageIO.read(new File("Strike!.png")));
               System.out.println(Strike.toString());
               Deck.cards.add(Strike);
               Cards Shinjutsu = new Attacks(3, 4, Effects.Return, Cards.Classs.Ninja, Cards.Rarity.Uncommon, ImageIO.read(new File("Shinjutsu.png")));
               System.out.println(Shinjutsu.toString());  
               Deck.cards.add(Shinjutsu);
        }
}'

The reason I don't just type 'System.out.println("Shuriken") is because I want to create more cards. Down below is another class which is a card-creator:

    public class Cards { 
    enum Classs {
        Wizard, Ninja, Lieutenant, Medic, Chemist, Godfather;
        private static final Classs[] classes = Classs.values();
        public static Classs getClass(int i) {
            return Classs.classes[i];
        }
    }
    enum Rarity {
        Common, Uncommon, Epic, Shadow;
        private static final Rarity[] rarities = Rarity.values();
        public static Rarity getClass(int i) {
            return Rarity.rarities[i];
        }
    }
    enum Mana {
        one,
        two, 
        three, 
        four,
        five,
        six,
        seven,
        eight,
        nine,
        ten,
        x;
        private static final Mana[] mana = Mana.values();
        public static Mana getMana(int i) {
            return Mana.mana[i];
        }
    }   

    public static int mana; 
    public static int energy;
    public static BufferedImage card;
    public static Classs class1;
    public static Rarity rarity;
    public static Effects effects;
    public Cards(int mana, Effects effects, Rarity rarity, Classs class1, BufferedImage card) {
        this.card = card;
        this.mana = mana;
        this.effects = effects;
        this.rarity = rarity;
        this.class1 = class1;
    }
public Classs getClasss() {
    return this.class1;
}public int getMana() {
    return this.mana;
}public Effects getEffects() {
    return this.effects;
}public Rarity getRarity() {
    return this.rarity;
}
      }'

Below is yet another class which serves a similar purpose as the cards class:

class Attacks extends Cards {   
public static int damage;
private final int mana;
private Effects effects;
public BufferedImage card;
private final Rarity rarity;
private final Classs class1;
Attacks(int damage, final int mana, final Effects effects, final Classs class1, final Rarity rarity, BufferedImage card) {
super(mana, effects, rarity, class1, card);
this.effects = effects; 
    this.damage = damage;
    this.rarity = rarity;
    this.class1 = class1;
    this.effects = effects;
    this.mana = mana;           
    this.card = card;
}

}'

And lastly, my enum:

    public enum Effects {
    Return;
    private static final Effects[] effects = Effects.values();
    public static Effects getEffects(int i) {
            return Effects.effects[i];
    }
}



Aucun commentaire:

Enregistrer un commentaire