-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a menu under the grid with WriteCommands(), a singleton random …
…cell state generator with the class RandomGenerator and a way to continously play until a button is pressed.
- Loading branch information
alessdangelo
committed
Jul 9, 2021
1 parent
a0d8f83
commit 23e3924
Showing
2 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//Author : alessdangelo | ||
//Date : 09/07/2021 | ||
//Description: Singleton class to generate a random number allowing to have only one instance of this class | ||
using System; | ||
|
||
namespace console_game_of_life | ||
{ | ||
/// <summary> | ||
/// Class generating a random number, using the singleton pattern | ||
/// </summary> | ||
public class RandomGenerator : Random | ||
{ | ||
/// <summary> | ||
/// Random object | ||
/// </summary> | ||
private Random _random; | ||
|
||
/// <summary> | ||
/// Current and only instance of RandomGenerator | ||
/// </summary> | ||
private static RandomGenerator _instance; | ||
|
||
/// <summary> | ||
/// Singleton, instanciate the random object | ||
/// </summary> | ||
private RandomGenerator(int seed) | ||
{ | ||
_random = new Random(seed); | ||
} | ||
|
||
/// <summary> | ||
/// Get current instance if exist, else instanciate it | ||
/// </summary> | ||
/// <returns>the singleton instance</returns> | ||
public static RandomGenerator GetInstance(int seed) | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new RandomGenerator(seed); | ||
return _instance; | ||
} | ||
return _instance; | ||
} | ||
} | ||
} |