Guest User

Untitled

a guest
Jul 5th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. class SeededRandom
  2.     {
  3.         private int seed;
  4.         private Random rand;
  5.  
  6.  
  7.  
  8.         public SeededRandom()
  9.         {
  10.             Random seedR = new Random();
  11.             seed = seedR.Next();
  12.             rand = new Random(seed);
  13.         }
  14.  
  15.         public SeededRandom(int seed)
  16.         {
  17.             this.seed = seed;
  18.             rand = new Random(seed);
  19.         }
  20.        
  21.  
  22.         public int GetSeed()
  23.             { return seed; }
  24.     }
  25.  
  26. class Map
  27.     {
  28.         public int map_w, map_h;
  29.         public Tile[,] map;
  30.         public SeededRandom rand;
  31.  
  32.  
  33.         public Map(int map_w, int map_h)
  34.         {
  35.             this.map_w = map_w;
  36.             this.map_h = map_h;
  37.             map = new Tile[map_h, map_w];
  38.             rand = new SeededRandom();
  39.         }
  40.  
  41.         public Map(int map_w, int map_h, int seed) : this(map_w, map_h)
  42.         {
  43.             rand = new SeededRandom(seed);
  44.         }
  45.  
  46.         public int GetSeed()
  47.             { return rand.GetSeed(); }
  48.     }
  49.  
  50. class BasicRandomMap : Map
  51.     {
  52.  
  53.         public BasicRandomMap(int map_w, int map_h) : base(map_w, map_h) { }
  54.         public BasicRandomMap(int map_w, int map_h, int seed) : base(map_w, map_h, seed) { }
  55.     }
  56.  
  57.  
  58. class Program
  59.     {
  60.         static void Main(string[] args)
  61.         {
  62.            
  63.             Map map1 = new Map(10, 10);
  64.             Map map2 = new Map(20, 20, map1.GetSeed());
  65.             BasicRandomMap map3 = new BasicRandomMap(10, 10);
  66.             BasicRandomMap map4 = new BasicRandomMap(20, 20, map3.GetSeed());
  67.             Console.WriteLine(map1.GetSeed());
  68.             Console.WriteLine(map2.GetSeed());
  69.             Console.WriteLine(map3.GetSeed());
  70.             Console.WriteLine(map4.GetSeed());
  71.         }
  72.     }
  73. ################
  74. Result:
  75. 1424215421
  76. 1424215421
  77. 1424215421
  78. 1424215421
Advertisement
Add Comment
Please, Sign In to add comment