Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #include <cstdlib>
- #include <time.h>
- const int N=10;
- void fillWithDots(char letters[][N], int n);
- void printMultiArray(char letters[][N],int n);
- void createRoute(char letters[][N], int n);
- int myRand(int max, int min);
- int main(){
- char a = 'A';
- char b = a++;
- printf("%c",b);
- srand(time(NULL));
- const unsigned N = 10;
- char letters[N][N];
- fillWithDots(letters,N);
- printMultiArray(letters,N);
- createRoute(letters,N);
- printMultiArray(letters,N);
- }
- void fillWithDots(char letters[][N], int n){
- for (int i = 0; i<n;i++){
- for (int j=0; j<N;j++){
- letters[i][j]='.';
- }
- }
- }
- void createRoute(char letters[][N], int n){ // 0 - NORTH, 1 - EAST, 2 SOUTH, 3 WEST
- int xPos=0;
- int yPos=0;
- char a = 'A';
- letters[xPos][yPos]=a;
- while (true){
- int direction = myRand(3,0);
- if (direction == 0){ // NORTH
- if (yPos-1>=0 && letters[xPos][yPos-1]=='.') yPos-1;
- else continue;
- }
- else if (direction == 1){ //EAST
- if (xPos+1<=N-1 && letters[xPos+1][yPos-1]=='.') xPos+1;
- else continue;
- }
- else if (direction == 2){ //SOUTH
- if (yPos+1<=N-1 && letters[xPos][yPos+1]=='.') yPos+1;
- else continue;
- }
- else if (direction == 3){ // WEST
- if (xPos-1>=0 && letters[xPos-1][yPos]=='.') xPos-1;
- }
- letters[xPos][yPos]=++a;
- if (a=='Z') break;
- }
- }
- int myRand(int max, int min){
- return rand()%(max-min + 1) + min;
- }
- void printMultiArray(char letters[][N],int n){
- for (int i = 0; i<n;i++){
- for (int j=0; j<N;j++){
- printf("%c",letters[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement