Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #define ROZMIAR 8
  3.  
  4. struct Wsp {
  5.     int x;
  6.     int y;
  7. };
  8.  
  9. struct Wsp znajdz_wina(int tablica[ROZMIAR][ROZMIAR])
  10. {
  11.     for (int i = 0; i < ROZMIAR; i++){
  12.         for (int j = 0; j < ROZMIAR; j++){
  13.             if (tablica[i][j] == 2){
  14.  
  15.                 struct Wsp wspol;
  16.                 wspol.x = i;
  17.                 wspol.y = j;
  18.  
  19.                 return wspol;
  20.             }
  21.         }
  22.     }
  23. }
  24.  
  25. struct Wsp znajdz_bohatera(int tablica[ROZMIAR][ROZMIAR])
  26. {
  27.     for (int i = 0; i < ROZMIAR; i++){
  28.         for (int j = 0; j < ROZMIAR; j++){
  29.             if (tablica[i][j] == 8){
  30.  
  31.                 struct Wsp wspol;
  32.                 wspol.x = i;
  33.                 wspol.y = j;
  34.  
  35.                 return wspol;
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. void ruch(int tablica[ROZMIAR][ROZMIAR], struct Wsp wspol_ruch, struct Wsp wspol_boh) {
  42.     struct Wsp tmp;
  43.  
  44.     tablica[wspol_boh.x][wspol_boh.y] = 1;
  45.     tablica[wspol_ruch.x][wspol_ruch.y] = 8;
  46.  
  47.     printf("Bohater przeniosl sie na wspolrzedne x: %d y: %d\n", wspol_ruch.x, wspol_ruch.y);
  48. }
  49.  
  50. void gora(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
  51. {
  52.     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)){
  53.         struct Wsp wsp_ruch;
  54.  
  55.         wsp_ruch.x = wsp_bohater.x - 1;
  56.         wsp_ruch.y = wsp_bohater.y;
  57.         printf("gora");
  58.  
  59.         ruch(tablica, wsp_ruch, wsp_bohater);
  60.     }
  61. }
  62.  
  63. void dol(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
  64. {
  65.     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)){
  66.         struct Wsp wsp_ruch;
  67.  
  68.         wsp_ruch.x = wsp_bohater.x + 1;
  69.         wsp_ruch.y = wsp_bohater.y;
  70.         printf("dol");
  71.  
  72.         ruch(tablica, wsp_ruch, wsp_bohater);
  73.     }
  74. }
  75.  
  76. void lewo(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
  77. {
  78.     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)){
  79.         struct Wsp wsp_ruch;
  80.  
  81.         wsp_ruch.x = wsp_bohater.x;
  82.         wsp_ruch.y = wsp_bohater.y - 1;
  83.         printf("lewo");
  84.  
  85.         ruch(tablica, wsp_ruch, wsp_bohater);
  86.     }
  87. }
  88.  
  89. void prawo(int tablica[ROZMIAR][ROZMIAR], struct Wsp wsp_bohater)
  90. {
  91.     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)){
  92.         struct Wsp wsp_ruch;
  93.  
  94.         wsp_ruch.x = wsp_bohater.x;
  95.         wsp_ruch.y = wsp_bohater.y + 1;
  96.         printf("prawo");
  97.  
  98.         ruch(tablica, wsp_ruch, wsp_bohater);
  99.     }
  100. }
  101.  
  102. int main()
  103. {
  104.     int tablica[ROZMIAR][ROZMIAR] = { {0, 0, 0, 0, 0, 0, 0, 0},
  105.                                       {0, 1, 1, 1, 1, 1, 1, 0},
  106.                                       {0, 1, 0, 0, 0, 0, 0, 0},
  107.                                       {0, 1, 0, 1, 1, 1, 1, 1},
  108.                                       {0, 1, 0, 1, 0, 0, 0, 0},
  109.                                       {0, 1, 0, 1, 2, 1, 1, 0},
  110.                                       {0, 1, 0, 1, 1, 1, 1, 0},
  111.                                       {8, 1, 0, 0, 0, 0, 0, 0}};
  112.  
  113.     struct Wsp bohater;
  114.     struct Wsp wygrana;
  115.  
  116.     bohater = znajdz_bohatera(tablica);
  117.     printf("%d\n", tablica[1][7]);
  118.     printf("Wspolrzedne bohatera: %d %d\n", bohater.x, bohater.y);
  119.  
  120.     wygrana = znajdz_wina(tablica);
  121.  
  122.     while(tablica[wygrana.x][wygrana.y] != 8) {
  123.         bohater = znajdz_bohatera(tablica);
  124.  
  125.         gora(tablica, bohater);
  126.         dol(tablica, bohater);
  127.         lewo(tablica, bohater);
  128.         prawo(tablica, bohater);
  129.  
  130.         printf("Aby znalezc kolejny ruch wcisnij dowolny klawisz \n");
  131.         getchar();
  132.     }
  133.  
  134.     printf("WYGRALES NIE MA WIECEJ RUCHOW UHUHUH YEAAAAA!!!!!11oneonene");
  135.  
  136.  
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement