I have very minimal experience programming and I'm trying to create a random(ish) class generator for my buddies and I on Warzone for fun. It's a very basic generator but I'm having some trouble figuring out how to get the outputs I want. It turned into a bigger project than I anticipated so I'll take any help I can get!
For anyone who hasn't played the game, there are at most 9 different classes of attachments you can choose from (i.e. suppressors, barrels, optics, stocks, etc) but you can only have a maximum of 5 equipped, meaning some attachment classes won't be used. I haven't added all the attachment categories or special attachments there might be since I'm trying to work out the basics first.
I'd like to have the final output be something like:
Primary Gun: M4A1
Primary Grip: Commando
Primary Laser: None
Primary Stock: No Stock Attachment
Primary Mag: 50
Primary Rear Grip: Stippled
Primary Barrel: Big Barrel
As of now it just outputs something like
Primary Gun: M4A1 Primary Attachments: Commando None No Stock Attachment 50 Stippled None
This is what I have so far (excuse if the code looks ugly lol)
import java.util.concurrent.ThreadLocalRandom;
public class RandomClass {
public static void main(String[] args) {
System.out.println("Primary: " + randomPrimaryGun());
System.out.println("Attachments: " + primaryAttachments());
System.out.println("Secondary: " + randomSecondaryGun());
}
public static String randomPrimaryGun() {
String[] primaryGuns = {"M4A1", "Kilo", "Grau", "Bruen", "FAL", "M13"};
int randIdx = ThreadLocalRandom.current().nextInt(primaryGuns.length);
String randPrimary = primaryGuns[randIdx];
return randPrimary;
}
public static String randomSecondaryGun() {
String[] secondaryGuns = {"MP5", "P90", "AUG", "Uzi", "MP7"};
int randIdx = ThreadLocalRandom.current().nextInt(secondaryGuns.length);
String randSecondary = secondaryGuns[randIdx];
return randSecondary;
}
public static String primaryAttachments() {
String[] primaryGrip = {"Merc ", "Ranger ", "Commando ", "None "};
String[] primaryLaser = {"Tac ", "5mw ", "None "};
String[] primaryStock = {"No Stock Attachment ", "No Stock ", "Fast stock "};
String[] primaryMag = {"50 ", "60 "};
String[] primaryRearGrip = {"Stippled ", "None "};
String[] primaryBarrel = {"Big Barrel", "Short Barrel"};
int randIdx0 = ThreadLocalRandom.current().nextInt(primaryGrip.length);
int randIdx1 = ThreadLocalRandom.current().nextInt(primaryLaser.length);
int randIdx2 = ThreadLocalRandom.current().nextInt(primaryStock.length);
int randIdx3 = ThreadLocalRandom.current().nextInt(primaryMag.length);
int randIdx4 = ThreadLocalRandom.current().nextInt(primaryRearGrip.length);
int randIdx5 = ThreadLocalRandom.current().nextInt(primaryBarrel.length);
String grip = primaryGrip[randIdx0];
String laser = primaryLaser[randIdx1];
String stock = primaryStock[randIdx2];
String mag = primaryMag[randIdx3];
String rearGrip = primaryRearGrip[randIdx4];
String barell = primaryBarrel[randIdx5];
}
}
I know I need some if/else statements and maybe some loops but I have no idea how to implement that with a random selection from a list. If anyone could at least help me get started I'd really appreciate it! Once I know the basic method I can go from there and add whatever else I need to!
I haven't bothered starting with the secondary attachments yet since I can't figure out how to do the primary attachments yet, but it'd essentially be the same code just with a few differences.
Thanks you!
Aucun commentaire:
Enregistrer un commentaire