mardi 6 octobre 2015

Random event system in C# . How to do it?

I am just a beginner in the world of programming, thus I have a simple question. Is it possible to randomly execute functions? If so, how would you do it? It is just a curiosity based on a thread I've read in another forum. Basically, the discussion was on how to generate random events for a game, and they commented about a "hack" used in some languages (especially AS3). The hack is to treat functions as variables. Example:

//Make an array of the functions
public function makeEarthquake():void{}
public function causePlague():void{}
public function spaceZombieAttack():void{}

//select at random
var selection:uint = Math.random() * eventArrray.length;
//Call it
eventArray[selection]();

I hope this is clear. I will be happy with any answer that can explain how to randomly call methods. Thank you.




Aucun commentaire:

Enregistrer un commentaire