Advertisement
Guest User

gen

a guest
Nov 22nd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10. [StructLayout(LayoutKind.Sequential)]
  11. public struct Point
  12. {
  13. public float X { get; set; }
  14. public float Y { get; set; }
  15.  
  16. public Point(float x, float y)
  17. : this()
  18. {
  19. X = x;
  20. Y = y;
  21. }
  22. }
  23.  
  24. class Program
  25. {
  26. static int[] grid = new int[10000];
  27.  
  28. static Point dimenzije = new Point(4, 4);
  29.  
  30. static void Main(string[] args)
  31. {
  32. Console.Write("Dimenzije: ");
  33. string ocitano = Console.ReadLine();
  34.  
  35. string[] dim = ocitano.Split();
  36.  
  37. dimenzije = new Point(Convert.ToInt16(dim[0]), Convert.ToInt16(dim[1]));
  38. ocitano = Console.ReadLine();
  39. algoritam();
  40. drawiksove();
  41. Console.ReadLine();
  42. }
  43. static void drawiksove()
  44. {
  45. string ispis = "";
  46. for (int i = 0; i < dimenzije.X * dimenzije.Y; i++)
  47. {
  48. if (i % (int)dimenzije.X == 0)
  49. {
  50. //Console.WriteLine(i);
  51. Console.Write('\n');
  52. }
  53.  
  54. Console.Write(grid[i]);
  55. }
  56.  
  57. Console.Write(ispis);
  58. }
  59. static void algoritam()
  60. {
  61. Random rand = new Random();
  62. Point pocetna = new Point(rand.Next((int)dimenzije.X), rand.Next((int)dimenzije.Y));
  63. for (int i = 0; i < dimenzije.X*dimenzije.Y; i++)
  64. {
  65. int broj = rand.Next(100);
  66. int brojPrepreke = rand.Next(4, 9);
  67. if (broj < 10)
  68. {
  69. grid[i]=brojPrepreke;
  70. }
  71. else if (broj < 18) {
  72. grid[i] = 1;
  73. }
  74. }
  75. int brojStartnePozicije = rand.Next((int)dimenzije.X * (int)dimenzije.Y - 5);
  76. while (brojStartnePozicije % dimenzije.X > 10)
  77. {
  78. brojStartnePozicije = rand.Next((int)dimenzije.X * (int)dimenzije.Y - 5);
  79. }
  80. grid[brojStartnePozicije] = 1;
  81. grid[brojStartnePozicije + 1] = 1;
  82. grid[brojStartnePozicije + 2] = 1;
  83. grid[brojStartnePozicije + 3] = 1;
  84. Console.Write(brojStartnePozicije%15);
  85. Console.Write("\n");
  86. Console.Write(brojStartnePozicije / 15);
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement