Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. #define a 20
  7. #define b 60
  8. char array[a][b];
  9.  
  10. void int_board() // Dem array das äußere Rechteck zugewiesen
  11. {
  12. for (int i = 0; i < a; i++)
  13. {
  14. for (int k = 0; k < b; k++)
  15. {
  16. if (i == 0 || i == (a-1) || k == 0 || k == (b-1))
  17. array[i][k] = '#';
  18. else
  19. array[i][k] = ' ';
  20. }
  21. }
  22. }
  23.  
  24. void f(int* apos, int* bpos, int* s) // Zur kontrolle ob der array seine Grenzen überschreitet!
  25. {
  26. while ((*apos + *s) > a - 2)
  27. *apos = *apos -1;
  28. while ((*bpos + *s) > b - 2)
  29. *bpos = *bpos -1;
  30. while (*apos < 2)
  31. *apos = *apos +1;
  32. while (*bpos < 2)
  33. *bpos = *bpos +1;
  34. }
  35.  
  36. void add_single_block() // Ein Block wird zwischen der Größe 3 und 6 wird in das innere des Rechtecks in das array eingefügt
  37. {
  38. int size;
  39. size = (rand() % 4 +3);
  40.  
  41.  
  42. int aposition, bposition;
  43. aposition = rand() % a + 1;
  44. bposition = rand() % b + 1;
  45.  
  46. f(&aposition, &bposition, &size); // Zur kontrolle ob der array seine Grenzen überschreitet!
  47.  
  48.  
  49.  
  50. for (int i = 0; i < size; i++)
  51. {
  52. for (int k = 0; k < size; k++)
  53. {
  54. array[i+aposition][k +bposition] = '#';
  55. }
  56. }
  57. }
  58.  
  59.  
  60. void show_game_board()
  61. {
  62. for (int i = 0; i < a; i++)
  63. {
  64. for (int k = 0; k <b; k++)
  65. {
  66. printf("%c", array[i][k]);
  67.  
  68. if (k == 59)
  69. printf("\n");
  70. }
  71. }
  72. }
  73.  
  74.  
  75.  
  76. main()
  77. {
  78. #
  79. char restart;
  80. do
  81. {
  82.  
  83. int_board(); //äußeres Rechteck wird array zugewiesen
  84.  
  85. for (int i = 1; i <= 20; i++) // 20 Mal wird zufällig im array ein Block hinzugeügt
  86. add_single_block(); // Dem array wird ein block hinzugefügt
  87.  
  88. show_game_board(); // Ausgabe des arrays
  89.  
  90. printf("\nDo you like to return? (Y/N)\n\n"); // Soll das ganze nochmal ausgegeben werden?
  91. restart = _getch();
  92.  
  93. }while (restart == 'Y' || restart == 'y');
  94.  
  95. printf("Press any key to exit =)");
  96.  
  97.  
  98. _getch();
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement