Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROZMIAR 8
- struct Wsp {
- int x;
- int y;
- };
- struct Wsp znajdz_wina(int tablica[ROZMIAR][ROZMIAR])
- {
- for (int i = 0; i < ROZMIAR; i++){
- for (int j = 0; j < ROZMIAR; j++){
- if (tablica[i][j] == 2){
- struct Wsp wspol;
- wspol.x = i;
- wspol.y = j;
- return wspol;
- }
- }
- }
- }
- struct Wsp znajdz_bohatera(int tablica[ROZMIAR][ROZMIAR])
- {
- for (int i = 0; i < ROZMIAR; i++){
- for (int j = 0; j < ROZMIAR; j++){
- if (tablica[i][j] == 8){
- struct Wsp wspol;
- wspol.x = i;
- wspol.y = j;
- return wspol;
- }
- }
- }
- }
- void ruch(int tablica[ROZMIAR][ROZMIAR], struct Wsp wspol_ruch, struct Wsp wspol_boh) {
- struct Wsp tmp;
- tablica[wspol_boh.x][wspol_boh.y] = 1;
- tablica[wspol_ruch.x][wspol_ruch.y] = 8;
- printf("Bohater przeniosl sie na wspolrzedne x: %d y: %d\n", wspol_ruch.x, wspol_ruch.y);
- }
- void gora(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
- {
- if (((tablica[wsp_bohater.x - 1][wsp_bohater.y] == 0) || (tablica[wsp_bohater.x - 1][wsp_bohater.y] == 2)) && (wsp_bohater.x - 1 > -1) && (wsp_bohater.x - 1 < ROZMIAR)){
- struct Wsp wsp_ruch;
- wsp_ruch.x = wsp_bohater.x - 1;
- wsp_ruch.y = wsp_bohater.y;
- printf("gora");
- ruch(tablica, wsp_ruch, wsp_bohater);
- }
- }
- void dol(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
- {
- if (((tablica[wsp_bohater.x + 1][wsp_bohater.y] == 0) || (tablica[wsp_bohater.x + 1][wsp_bohater.y] == 2)) && (wsp_bohater.x + 1 > -1) && (wsp_bohater.x + 1 < ROZMIAR)){
- struct Wsp wsp_ruch;
- wsp_ruch.x = wsp_bohater.x + 1;
- wsp_ruch.y = wsp_bohater.y;
- printf("dol");
- ruch(tablica, wsp_ruch, wsp_bohater);
- }
- }
- void lewo(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
- {
- if (((tablica[wsp_bohater.x][wsp_bohater.y - 1] == 0) || (tablica[wsp_bohater.x][wsp_bohater.y - 1] == 2)) && (wsp_bohater.y - 1 > -1) && (wsp_bohater.y - 1 < ROZMIAR)){
- struct Wsp wsp_ruch;
- wsp_ruch.x = wsp_bohater.x;
- wsp_ruch.y = wsp_bohater.y - 1;
- printf("lewo");
- ruch(tablica, wsp_ruch, wsp_bohater);
- }
- }
- void prawo(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
- {
- if (((tablica[wsp_bohater.x][wsp_bohater.y + 1] == 0) || (tablica[wsp_bohater.x][wsp_bohater.y + 1] == 2)) && (wsp_bohater.y + 1 > -1) && (wsp_bohater.y + 1 < ROZMIAR)){
- struct Wsp wsp_ruch;
- wsp_ruch.x = wsp_bohater.x;
- wsp_ruch.y = wsp_bohater.y + 1;
- printf("prawo");
- ruch(tablica, wsp_ruch, wsp_bohater);
- }
- }
- int main()
- {
- int tablica[ROZMIAR][ROZMIAR] = { {0, 0, 0, 0, 0, 0, 0, 0},
- {0, 1, 1, 1, 1, 1, 1, 0},
- {0, 1, 0, 0, 0, 0, 0, 0},
- {0, 1, 0, 1, 1, 1, 1, 1},
- {0, 1, 0, 1, 0, 0, 0, 0},
- {0, 1, 0, 1, 2, 1, 1, 0},
- {0, 1, 0, 1, 1, 1, 1, 0},
- {8, 1, 0, 0, 0, 0, 0, 0}};
- struct Wsp bohater;
- struct Wsp wygrana;
- bohater = znajdz_bohatera(tablica);
- printf("%d\n", tablica[1][7]);
- printf("Wspolrzedne bohatera: %d %d\n", bohater.x, bohater.y);
- wygrana = znajdz_wina(tablica);
- while(tablica[wygrana.x][wygrana.y] != 8) {
- bohater = znajdz_bohatera(tablica);
- gora(tablica, bohater);
- dol(tablica, bohater);
- lewo(tablica, bohater);
- prawo(tablica, bohater);
- printf("Aby znalezc kolejny ruch wcisnij dowolny klawisz \n");
- getchar();
- }
- printf("WYGRALES NIE MA WIECEJ RUCHOW UHUHUH YEAAAAA!!!!!11oneonene");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement