Advertisement
Guest User

PK

a guest
Mar 27th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7. int plansza [10][10] = {
  8. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  9. {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  10. {1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
  11. {1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
  12. {1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
  13. {1, 0, 1, 0, 1, 2, 1, 1, 0, 1},
  14. {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
  15. {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
  16. {1, 8, 1, 0, 0, 0, 1, 0, 0, 1},
  17. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  18. };
  19.  
  20. int pole [10][10] = {
  21. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  22. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  23. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  24. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  25. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  26. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  27. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  28. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  29. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  30. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  31. };
  32.  
  33. int i,j; // zmienne pomocnicze
  34. int x=8; // wspolrzedna x
  35. int y=1; // wspolrzedna y
  36. int p;
  37. printf("Oto twoja plansza, liczba 8 oznacza miejsce startu, liczba 2 - koniec\n\n");
  38. printf(" 1 2 3 4 5 6 7 8 9 10\n");
  39.  
  40. for(i=0; i<10; i++)
  41. {
  42.  
  43. printf("\n");
  44. if (i==9)
  45. printf("%d ",i+1);
  46. else
  47. printf("%d ",i+1);
  48.  
  49. for(j=0; j<10; j++)
  50. printf ("%d ", plansza[i][j]);
  51.  
  52. }
  53.  
  54. printf ("\n \n");
  55.  
  56. // czesc wypisujaca
  57.  
  58.  
  59. do
  60. {
  61. if (plansza[x-1][y] == 0)
  62. {
  63. pole[x-1][y] = 1;
  64. plansza[x-1][y] = 1;
  65. x--;
  66. printf("w gore\n");
  67. }
  68. else
  69.  
  70. if (plansza[x][y+1] == 0)
  71. {
  72. pole[x][y+1] = 1;
  73. plansza[x][y+1] = 1;
  74. y++;
  75. printf("w prawo\n");
  76.  
  77. }
  78. else
  79.  
  80. if (plansza[x+1][y] == 0)
  81. {
  82. pole[x+1][y] = 1;
  83. plansza[x+1][y] = 1;
  84. x++;
  85. printf("w dol\n");
  86.  
  87. }
  88. else
  89.  
  90. if (plansza[x][y-1] == 0)
  91. {
  92. pole[x][y-1] = 1;
  93. plansza[x][y-1] = 1;
  94. y--;
  95. printf("w lewo\n");
  96.  
  97. }
  98. else //cofanie
  99. if (pole[x-1][y] == 1)
  100. {
  101. pole[x][y] = 0;
  102. x--;
  103. printf("cofam w gore\n");
  104. }
  105. else
  106. if (pole[x][y+1] == 1)
  107. {
  108. pole[x][y] = 0;
  109. y++;
  110. printf("cofam w prawo\n");
  111. }
  112. else
  113. if (pole[x+1][y] == 1)
  114. {
  115. pole[x][y] = 0;
  116. x++;
  117. printf("cofam w dol\n");
  118. }
  119. else
  120. if (pole[x][y-1] == 1)
  121. {
  122. pole[x][y] = 0;
  123. y--;
  124. printf("cofam w lewo\n");
  125. }
  126.  
  127.  
  128.  
  129.  
  130. }
  131. while (plansza[x][y] != 2);
  132.  
  133.  
  134. printf(" 1 2 3 4 5 6 7 8 9 10\n");
  135.  
  136. for(i=0; i<10; i++)
  137. {
  138. printf("\n");
  139. if (i==9)
  140. printf("%d ",i+1);
  141. else
  142. printf("%d ",i+1);
  143.  
  144. for(j=0; j<10; j++)
  145. {
  146. if (pole[i][j] == 1)
  147. printf ("%d ", pole[i][j]);
  148. else
  149. printf(" ") ;
  150. }
  151.  
  152.  
  153. }
  154.  
  155.  
  156.  
  157. return 0;
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement