lundi 24 octobre 2016

Picking random objects from class

So I have made these objects from my class Player

Player Silva = new Player("André Silva", 2, 5);
Player Moses = new Player("Victor Moses", 3, 3);
Player Batshuayi = new Player("Michy Batshuayi", 3, 4);
Player Medel = new Player("Gary Medel", 4, 4);

And then I have objects made from my class Club (Dont worry about the values in any of these, just football related stuff for those who does not know)

Club Barcelona = new Club("FC Barcelona", 5);
Club RealMadrid = new Club("Real Madrid", 5);
Club Inter = new Club("Inter", 4);
Club Liverpool = new Club("Liverpool", 4);

Anyways, I would like to random slump one of the players, and one of the clubs and compare their values in an if statement. As of now I have put all of these in arrays

int[] Playerability = {Silva.ability,Moses.ability,Batshuayi.ability,Medel.ability};
int[] Clubrating = { Barcelona.clubrating, RealMadrid.clubrating, Inter.clubrating};

So I can use a simple random and put that variable in the array

int randomclub = randomnumber.Next(16);
int randomplayer = randomnumber.Next(28);

if (Playerability[randomplayer] >= Clubrating[randomclub] ||
    Playerpotential[randomplayer] >= Clubrating[randomclub])

but this seems very innefective if I want many more objects, so I am wondering if there is an easier solution to this? Sorry if its obvious but I cant seem to find it. Language is c# btw




Aucun commentaire:

Enregistrer un commentaire