This is my first java project so I am still learning a large amount of stuff and how to apply it.
I am making a random load out creator for Titanfall 2 that uses
double b = (int)(Math.random() * 6 + 1);
to randomly generate a number for which ever variable i use for each set of things I randomize. Based on what the number is, a different text will be displayed, one number for each possible selection in game. My problem is that since you can have two mods for each gun both gun mod blocks in the code are the same but if by chance both random numbers for the mods are the same it displays the same mod, which you cannot do in game. I would like to make it so if b==a then it re-randomizes b, but I cannot figure out how to do this. The entire code will be at the bottom and a picturing showing what i want to avoid, the issue occurs with Gun mod 1 and Gun mod 2, bluej syas that variable b is already defined when I tried to put it the second in the if (b==a)
//Tacticals
double t = (int)(Math.random() * 7 + 1);
if (t == 1) {
System.out.println("Tactical: Cloak");
}
if (t == 2) {
System.out.println("Tactical: Pulse Blade");
}
if (t == 3) {
System.out.println("Tactical: Grappling Hook");
}
if (t == 4) {
System.out.println("Tactical: Stim");
}
if (t == 5) {
System.out.println("Tactical: A-Wall");
}
if (t == 6) {
System.out.println("Tactical: Phase Shift");
}
if (t == 7) {
System.out.println("Tactical: Holo Pilot");
}
//Ordinance
double o = (int)(Math.random() * 6 + 1);
if (o == 1) {
System.out.println("Ordinance: Frag Grenade");
}
if (o == 2) {
System.out.println("Ordinance: Arc Grenade");
}
if (o == 3) {
System.out.println("Ordinance: Fire Star");
}
if (o == 4) {
System.out.println("Ordinance: Gravity Star");
}
if (o == 5) {
System.out.println("Ordinance: Electric Smoke Grenade");
}
if (o == 6) {
System.out.println("Ordinance: Satchel Charge");
}
//Primaries
double p = (int)(Math.random() * 22 + 1);
if (p == 1) {
System.out.println("Primary: R201");
}
if (p == 2) {
System.out.println("Primary: R101");
}
if (p == 3) {
System.out.println("Primary: G2");
}
if (p == 4) {
System.out.println("Primary: Hemlock");
}
if (p == 5) {
System.out.println("Primary: Flatline");
}
if (p == 6) {
System.out.println("Primary: Alternator");
}
if (p == 7) {
System.out.println("Primary: CAR");
}
if (p == 8) {
System.out.println("Primary: R-97");
}
if (p == 10) {
System.out.println("Primary: Volt");
}
if (p == 11) {
System.out.println("Primary: L-STAR");
}
if (p == 12) {
System.out.println("Primary: Spitfire");
}
if (p == 13) {
System.out.println("Primary: Devotion");
}
if (p == 14) {
System.out.println("Primary: Double Take");
}
if (p == 15) {
System.out.println("Primary: Kraber");
}
if (p == 16) {
System.out.println("Primary: DMR");
}
if (p == 17) {
System.out.println("Primary: EVA-8");
}
if (p == 18) {
System.out.println("Primary: Mastiff");
}
if (p == 19) {
System.out.println("Primary: Cold War");
}
if (p == 20) {
System.out.println("Primary: EPG");
}
if (p == 21) {
System.out.println("Primary: Softball");
}
if (p == 22) {
System.out.println("Primary: SMR");
}
//Primay Gun Mod 1
double a = (int)(Math.random() * 6 + 1);
if (a == 1) {
System.out.println("Gun Mod 1: Extra Ammo");
}
if (a == 2) {
System.out.println("Gun Mod 1: Speed Reload");
}
if (a == 3) {
System.out.println("Gun Mod 1: Gunrunner");
}
if (a == 4) {
System.out.println("Gun Mod 1: Gun Ready");
}
if (a == 5) {
System.out.println("Gun Mod 1: Fast Swap");
}
if (a == 6) {
System.out.println("Gun Mod 1: Tactikill");
}
//Primary Gun Mod 2
double b = (int)(Math.random() * 6 + 1);
if (b ==a) {
double b = (int)(Math.random() * 6 + 1);
}
if (b == 1) {
System.out.println("Gun Mod 2: Extra Ammo");
}
if (b== 2) {
System.out.println("Gun Mod 2: Speed Reload");
}
if (b== 3) {
System.out.println("Gun Mod 2: Gunrunner");
}
if (b== 4) {
System.out.println("Gun Mod 2: Gun Ready");
}
if (b== 5) {
System.out.println("Gun Mod 2: Fast Swap");
}
if (b== 6) {
System.out.println("Gun Mod 1: Tactikill");
}
// Secondary
double s = (int)(Math.random() * 5 + 1);
if (s==1) {
System.out.println("Secondary: RE .45");
}
if (s==2) {
System.out.println("Secondary: Hammond P2016");
}
if (s==3) {
System.out.println("Secondary: Wingman Elite");
}
if (s==4) {
System.out.println("Secondary: Mozambique ");
}
if (s==5) {
System.out.println("Secondary: Wingman B3");
}
//Pilot Kit 1
double c = (int)(Math.random() * 4 +1);
if (c==1) {
System.out.println("Pilot Kit 1: Power Cell");
}
if (c==2) {
System.out.println("Pilot Kit 1: Fast Regeneration");
}
if (c==3) {
System.out.println("Pilot Kit 1: Ordinance Expert");
}
if (c==4) {
System.out.println("Pilot Kit 1: Phase Embark");
}
// Pilot Kit 2
double d = (int)(Math.random() * 4 + 1);
if (d==1) {
System.out.println("Pilot Kit 2: Wall Hang");
}
if (d==2) {
System.out.println("Pilot Kit 2: Kill Report");
}
if (d==3) {
System.out.println("Pilot Kit 2: Hover");
}
if (d==4) {
System.out.println("Pilot Kit 2: Low Profile");
}
}
}
Aucun commentaire:
Enregistrer un commentaire