Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define SIZE 7
  5.  
  6. int position_x, position_y;
  7. int x,y;
  8.  
  9. int tablica[SIZE][SIZE] =   {{0, 0, 0, 0, 0, 0, 0, 0 },
  10.                             { 0, 1, 1, 1, 1, 1, 1, 0 },
  11.                             { 0, 1, 0, 0, 0, 0, 0, 0 },
  12.                             { 0, 1, 0, 1, 1, 1, 1, 1 },
  13.                             { 0, 1, 0, 1, 0, 0, 0, 0 },
  14.                             { 0, 1, 0, 1, 2, 1, 1, 0 },
  15.                             { 0, 1, 0, 1, 1, 1, 1, 0 },
  16.                             { 8, 1, 0, 0, 0, 0, 0, 0 }};
  17.  
  18. int stos[10];
  19.  
  20. gora();
  21. dol();
  22. prawo();
  23. lewo();
  24.  
  25.  
  26.  
  27. int gora(int position_y, int tablica)
  28. {
  29.  
  30.     if (position_y + 1 == 0 && position_y + 1 <= SIZE)
  31.     {
  32.         return 1;
  33.     }
  34.     else
  35.         return 0;
  36. }
  37.  
  38. int dol(int position_y, int tablica)
  39. {
  40.  
  41.     if (position_y - 1 == 0 && position_y - 1 <= SIZE)
  42.     {
  43.         return 1;
  44.     }
  45.     else
  46.         return 0;
  47. }
  48.  
  49. int lewo (int position_x, int tablica)
  50. {
  51.     if (position_x + 1 == 0 && position_x + 1 <= SIZE)
  52.     {
  53.         return 1;
  54.     }
  55.     else
  56.         return 0;
  57. }
  58.  
  59. int prawo (int position_x, int tablica)
  60. {
  61.     if (position_x - 1 == 0 && position_x - 1 <= SIZE)
  62.     {
  63.         return 1;
  64.     }
  65.     else
  66.         return 0;
  67. }
  68.  
  69.  
  70.  
  71. int main()
  72. {
  73. position_x = 0;
  74. position_y = 7;
  75.  
  76.  
  77. while ( tablica[position_x][position_y]!= 2)
  78. {
  79.  
  80.  
  81.  
  82.     if (gora(position_y, tablica));
  83.     {
  84.         position_y = position_y + 1;
  85.  
  86.     elseif(dol(position_y, tablica));
  87.     {
  88.         position_y = position_y - 1;
  89.  
  90.     elseif(lewo(position_x, tablica));
  91.     {
  92.         position_x = position_x - 1;
  93.  
  94.     elseif(prawo(position_x, tablica));
  95.     {
  96.         position_x = position_x + 1;
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement