Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. namespace ConsoleApp5
  9. {
  10.  
  11. /*TODO
  12. * Rewrite the array of blocks and positions as a dictionary?
  13. *
  14. *
  15. * */
  16.  
  17. class Block
  18. {
  19. public enum BlockType
  20. {
  21. Dirt,
  22. Ground
  23. }
  24. BlockType blockType;
  25. bool IsWalkable = false;
  26. char Icon = ' ';
  27. Pos Position;
  28.  
  29. public Block(BlockType _blocktype, bool _isWalkable, char _icon, Pos _pos)
  30. {
  31. blockType = _blocktype;
  32. IsWalkable = _isWalkable;
  33. Icon = _icon;
  34. Position = _pos;
  35. }
  36.  
  37. public String GetBlockType
  38. {
  39. get { return blockType.ToString(); }
  40. }
  41.  
  42. public Pos Pos
  43. {
  44. get { return Position; }
  45. }
  46.  
  47. public Char BlockIcon
  48. {
  49. get { return Icon; }
  50. }
  51. }
  52.  
  53. class Program
  54. {
  55.  
  56. int MapSize = 10;
  57. char dirt = '#';
  58. char ground = '.';
  59. Pos[] pos;
  60. List<Block> blocks;
  61.  
  62.  
  63. static void Main(string[] args)
  64. {
  65. Program p = new Program();
  66.  
  67.  
  68. p.BeginGenerating();
  69. }
  70.  
  71. void BeginGenerating()
  72. {
  73. Console.Write("Enter the wanted size of the map in a number (3-29) : ");
  74. MapSize = Convert.ToInt32(Console.ReadLine());
  75. if (MapSize > 29)
  76. MapSize = 29;
  77. if (MapSize < 3)
  78. MapSize = 3;
  79. Console.Clear();
  80. Console.Write("Enter a map seed : ");
  81. int seed = Convert.ToInt32(Console.ReadLine());
  82. Console.Clear();
  83. Random rand = new Random(seed);
  84. pos = new Pos[MapSize];
  85. blocks = new List<Block>();
  86. for (int x = 0; x < MapSize*2; x++)
  87. {
  88. for (int y = 0; y < MapSize; y++)
  89. {
  90.  
  91. Console.SetCursorPosition(GetPosition(x), GetPosition(y));
  92. pos[y] = new Pos(GetPosition(x), GetPosition(y));
  93. Block tempBlock;
  94. if (((y > 0 && y < MapSize - 1) && (x > 0 && x < MapSize * 2 - 1)))
  95. {
  96. tempBlock = new Block(Block.BlockType.Ground, true, ground, pos[y]);
  97. blocks.Add(tempBlock);
  98. }
  99. else
  100. {
  101. tempBlock = new Block(Block.BlockType.Dirt, false, dirt, pos[y]);
  102. blocks.Add(tempBlock);
  103. }
  104. Console.Write(tempBlock.BlockIcon);
  105. }
  106. }
  107.  
  108. /*for (int x = 0; x < MapSize * 2; x++)
  109. {
  110. for (int y = 0; y < MapSize; y++)
  111. {
  112.  
  113. if ((!(y > 0 && y < MapSize - 1) && !(x > 0 && x < MapSize * 2 - 1)))
  114. {
  115. int rndNum = rand.Next(1, 100);
  116. if(rndNum < 25)
  117. {
  118.  
  119. }
  120. }
  121.  
  122. }
  123. }*/
  124.  
  125. Console.WriteLine();
  126. int repeat = 0;
  127. for(int i = 0; i < blocks.Count;i++)
  128. {
  129. if(repeat >= 8)
  130. {
  131. repeat = 0;
  132. Console.WriteLine();
  133. }
  134. Console.Write(blocks[i].GetBlockType + "[" + blocks[i].Pos.PosX + "," + blocks[i].Pos.PosY + "] ");
  135. repeat++;
  136. }
  137.  
  138. Console.ReadLine();
  139. }
  140.  
  141.  
  142. int GetPosition(int num)
  143. {
  144. int position = (Console.WindowWidth / 2) + num;
  145. return num;
  146. }
  147. }
  148.  
  149. struct Pos
  150. {
  151. int x;
  152. int y;
  153.  
  154. public Pos(int _x, int _y)
  155. {
  156. x = _x;
  157. y = _y;
  158. }
  159.  
  160. public int PosX
  161. {
  162. get { return x; }
  163. }
  164. public int PosY
  165. {
  166. get { return y; }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement