Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int plansza [10][10] = {
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
- {1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
- {1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
- {1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
- {1, 0, 1, 0, 1, 2, 1, 1, 0, 1},
- {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
- {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
- {1, 8, 1, 0, 0, 0, 1, 0, 0, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- };
- int pole [10][10] = {
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- };
- int i,j; // zmienne pomocnicze
- int x=8; // wspolrzedna x
- int y=1; // wspolrzedna y
- int p;
- printf("Oto twoja plansza, liczba 8 oznacza miejsce startu, liczba 2 - koniec\n\n");
- printf(" 1 2 3 4 5 6 7 8 9 10\n");
- for(i=0; i<10; i++)
- {
- printf("\n");
- if (i==9)
- printf("%d ",i+1);
- else
- printf("%d ",i+1);
- for(j=0; j<10; j++)
- printf ("%d ", plansza[i][j]);
- }
- printf ("\n \n");
- // czesc wypisujaca
- do
- {
- if (plansza[x-1][y] == 0)
- {
- pole[x-1][y] = 1;
- plansza[x-1][y] = 1;
- x--;
- printf("w gore\n");
- }
- else
- if (plansza[x][y+1] == 0)
- {
- pole[x][y+1] = 1;
- plansza[x][y+1] = 1;
- y++;
- printf("w prawo\n");
- }
- else
- if (plansza[x+1][y] == 0)
- {
- pole[x+1][y] = 1;
- plansza[x+1][y] = 1;
- x++;
- printf("w dol\n");
- }
- else
- if (plansza[x][y-1] == 0)
- {
- pole[x][y-1] = 1;
- plansza[x][y-1] = 1;
- y--;
- printf("w lewo\n");
- }
- else //cofanie
- if (pole[x-1][y] == 1)
- {
- pole[x][y] = 0;
- x--;
- printf("cofam w gore\n");
- }
- else
- if (pole[x][y+1] == 1)
- {
- pole[x][y] = 0;
- y++;
- printf("cofam w prawo\n");
- }
- else
- if (pole[x+1][y] == 1)
- {
- pole[x][y] = 0;
- x++;
- printf("cofam w dol\n");
- }
- else
- if (pole[x][y-1] == 1)
- {
- pole[x][y] = 0;
- y--;
- printf("cofam w lewo\n");
- }
- }
- while (plansza[x][y] != 2);
- printf(" 1 2 3 4 5 6 7 8 9 10\n");
- for(i=0; i<10; i++)
- {
- printf("\n");
- if (i==9)
- printf("%d ",i+1);
- else
- printf("%d ",i+1);
- for(j=0; j<10; j++)
- {
- if (pole[i][j] == 1)
- printf ("%d ", pole[i][j]);
- else
- printf(" ") ;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement