My question is, how to generate a random challenge with given number (4-8) of trials ? I dont have any idea how to do that.
A challenge is built from trials(see in code).
The Trials are the attributes of Challenge class, built from an enum and an EnumMap
So when I get a random number of Integer in main (like r.nextInt(4)+4;) i will generate that number of trials for a challenge like
Weapons=25;
Hacking=32;
Vehicle=34;
Speed=56;
So for 1 Challenge, I dont need all the trials, just some of them. But I still need the possibility to choos from them randomly(4-8).
How can I generate these random Challenge objects with given number of attributes(and the values of them)? So basically some of them, from ALL of them.
Is this all wrong ?How should I start it ?
The code so far:
import java.util.*;
public class Challenge {
Random r = new Random();
// DRIVE, VEHICLE, ACCURACY, WEAPONS, REFLEX, STRATEGY, CHARISMA, HACKING,
// SPEED, STEALTH;
public static enum Trial {
DRIVE, VEHICLE, ACCURACY, WEAPONS, REFLEX, STRATEGY, CHARISMA, HACKING, SPEED, STEALTH;
}
Map<Trial, Integer> challenge = new EnumMap<Trial, Integer>(Trial.class);
public Challenge() {
challenge.put(Trial.DRIVE, r.nextInt(100) + 25);
challenge.put(Trial.VEHICLE, r.nextInt(100) + 25);
challenge.put(Trial.ACCURACY, r.nextInt(100) + 25);
challenge.put(Trial.WEAPONS, r.nextInt(100) + 25);
challenge.put(Trial.REFLEX, r.nextInt(100) + 25);
challenge.put(Trial.STRATEGY, r.nextInt(100) + 25);
challenge.put(Trial.CHARISMA, r.nextInt(100) + 25);
challenge.put(Trial.HACKING, r.nextInt(100) + 25);
challenge.put(Trial.SPEED, r.nextInt(100) + 25);
challenge.put(Trial.STEALTH, r.nextInt(100) + 25);
}
List<Trial> keys = new ArrayList<Trial>(challenge.keySet());
Trial randomKey = keys.get(r.nextInt(keys.size()));
Integer value = challenge.get(randomKey);
}
Aucun commentaire:
Enregistrer un commentaire