/*------------------------------------------------------------- * void Change_Die_Seed(object, EventArgs): * Changes the RNG's seed in the instance of the die. * ------------------------------------------------------------*/ private void Change_Die_Seed(object sender, EventArgs e) { //Attempts to convert the string in the SeedTextBox to an int // -If it succeeds, a new variable "seedValue" will hold the // value of the parsed string [Denoted by the "out" key word] if (!Int32.TryParse(SeedTextBox.Text, out int seedValue)) { //If the Parsing fails, send out an error message Error_Message_Label.Text = "ERROR: Seed needs to be an integer"; Error_Message_Label.Visible = true; //And disable the roll button Roll_Button.Enabled = false; return; } //If the error message is visible if (Error_Message_Label.Visible) { //Then make the error message invisible Error_Message_Label.Visible = false; Error_Message_Label.Text = ""; //And enable the Roll button Roll_Button.Enabled = true; } //Get an RNG with a new seed value rng = aRNG.Instance(seedValue); }
/*------------------------------------------------------------- * aRNG Instance(seed): * returns the static instance of the rng * ------------------------------------------------------------*/ public static aRNG Instance(int seed) { //If there is no RNG instance if (instance == null) { //Create one with the seed parameter and return it instance = new aRNG(seed); return(instance); } else { //If not, then check the seed if (instance.SEED != seed) { /*If the current seed is not the same as the * new seed, then create a new RNG*/ instance = new aRNG(seed); //Return the new instance return(instance); } else { //Return the instance if all fails return(instance); } } }
//Constructor of a deck of Cards public aDeckOfCards() { //Gets the RNG instance rng = aRNG.Instance(); //Creates a deck and shuffles the cards ResetDeck(); //Console.WriteLine("Deck completed and created"); }
//Seed value //Singleton works because of private constructor public aDie() { rng = aRNG.Instance(); }
//Private constructor that accepts a seed public aCoin() { rng = aRNG.Instance(); }