samedi 6 juillet 2019

Can I use Random method on a class with several instances?

I'm trying to create a Player class that will randomly pick one of the Combatants in a different class and use it. All included in a Pokemon game I'm learning to create.

Right now I'm just trying to figure out if its possible to make a Random method to pick one of the combatants and setting it to player1( for example )


public class combatantList extends Combatant {
     Combatant Gengar = new Combatant("Gengar", 40, 33, 30, 6);
     Combatant Charizard = new Combatant("Charizard", 45, 35, 100, 6);
     Combatant Venasaur = new Combatant("Venasaur", 40 , 50, 100, 3);
     Combatant Pikachu = new Combatant("Pikachu", 35, 25, 100, 7);
     Combatant Dito = new Combatant("Dito", 10 , 20 ,100, 4); 
 }


Is the best way to handle these are to set them up in an array? and then use a Random method? or should I be using a random method inside a Battle class or such?




Aucun commentaire:

Enregistrer un commentaire