Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SeededRandom
- {
- private int seed;
- private Random rand;
- public SeededRandom()
- {
- Random seedR = new Random();
- seed = seedR.Next();
- rand = new Random(seed);
- }
- public SeededRandom(int seed)
- {
- this.seed = seed;
- rand = new Random(seed);
- }
- public int GetSeed()
- { return seed; }
- }
- class Map
- {
- public int map_w, map_h;
- public Tile[,] map;
- public SeededRandom rand;
- public Map(int map_w, int map_h)
- {
- this.map_w = map_w;
- this.map_h = map_h;
- map = new Tile[map_h, map_w];
- rand = new SeededRandom();
- }
- public Map(int map_w, int map_h, int seed) : this(map_w, map_h)
- {
- rand = new SeededRandom(seed);
- }
- public int GetSeed()
- { return rand.GetSeed(); }
- }
- class BasicRandomMap : Map
- {
- public BasicRandomMap(int map_w, int map_h) : base(map_w, map_h) { }
- public BasicRandomMap(int map_w, int map_h, int seed) : base(map_w, map_h, seed) { }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Map map1 = new Map(10, 10);
- Map map2 = new Map(20, 20, map1.GetSeed());
- BasicRandomMap map3 = new BasicRandomMap(10, 10);
- BasicRandomMap map4 = new BasicRandomMap(20, 20, map3.GetSeed());
- Console.WriteLine(map1.GetSeed());
- Console.WriteLine(map2.GetSeed());
- Console.WriteLine(map3.GetSeed());
- Console.WriteLine(map4.GetSeed());
- }
- }
- ################
- Result:
- 1424215421
- 1424215421
- 1424215421
- 1424215421
Advertisement
Add Comment
Please, Sign In to add comment