Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- #define a 20
- #define b 60
- char array[a][b];
- void int_board() // Dem array das äußere Rechteck zugewiesen
- {
- for (int i = 0; i < a; i++)
- {
- for (int k = 0; k < b; k++)
- {
- if (i == 0 || i == (a-1) || k == 0 || k == (b-1))
- array[i][k] = '#';
- else
- array[i][k] = ' ';
- }
- }
- }
- void f(int* apos, int* bpos, int* s) // Zur kontrolle ob der array seine Grenzen überschreitet!
- {
- while ((*apos + *s) > a - 2)
- *apos = *apos -1;
- while ((*bpos + *s) > b - 2)
- *bpos = *bpos -1;
- while (*apos < 2)
- *apos = *apos +1;
- while (*bpos < 2)
- *bpos = *bpos +1;
- }
- 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
- {
- int size;
- size = (rand() % 4 +3);
- int aposition, bposition;
- aposition = rand() % a + 1;
- bposition = rand() % b + 1;
- f(&aposition, &bposition, &size); // Zur kontrolle ob der array seine Grenzen überschreitet!
- for (int i = 0; i < size; i++)
- {
- for (int k = 0; k < size; k++)
- {
- array[i+aposition][k +bposition] = '#';
- }
- }
- }
- void show_game_board()
- {
- for (int i = 0; i < a; i++)
- {
- for (int k = 0; k <b; k++)
- {
- printf("%c", array[i][k]);
- if (k == 59)
- printf("\n");
- }
- }
- }
- main()
- {
- #
- char restart;
- do
- {
- int_board(); //äußeres Rechteck wird array zugewiesen
- for (int i = 1; i <= 20; i++) // 20 Mal wird zufällig im array ein Block hinzugeügt
- add_single_block(); // Dem array wird ein block hinzugefügt
- show_game_board(); // Ausgabe des arrays
- printf("\nDo you like to return? (Y/N)\n\n"); // Soll das ganze nochmal ausgegeben werden?
- restart = _getch();
- }while (restart == 'Y' || restart == 'y');
- printf("Press any key to exit =)");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement