Advertisement
Guest User

ddd

a guest
Nov 30th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. const char kolumny = 20, wiersze = 20;
  6. unsigned char player = {88};
  7. unsigned char klawisz;
  8.  
  9.  
  10. void wypiszLabirynt(char lab[kolumny][wiersze], int n, int m)
  11. {
  12. system("cls");
  13. for(int i=0;i<n;i++)
  14. {
  15. for(int j=0;j<m;j++)
  16. {
  17. cout << lab[i][j];
  18. }
  19. cout << endl;
  20. }
  21. }
  22.  
  23. char menu()
  24. {
  25.  
  26. system("cls");
  27. cout << "Nacisnij:" << endl
  28. << "1 - labirynt 1" << endl
  29. << "2 - labirynt 2" << endl
  30. << "3 - labirynt 3" << endl
  31. << "? - aby uzyskac pomoc" << endl;
  32.  
  33. char wybor;
  34. cin >> wybor;
  35. return wybor;
  36. }
  37.  
  38.  
  39. void pomoc()
  40. {
  41. system("CLS");
  42. cout << "Dostepne klawisze: " << endl
  43. << "w - ruch w gore" << endl
  44. << "s - ruch w dol" << endl
  45. << "a - ruch w lewo" << endl
  46. << "d - ruch w prawo" << endl
  47. << "q - zamkniecie programu" << endl
  48. << "? - otwarcie pomocy" << endl;
  49. }
  50.  
  51.  
  52. void poziom(char lab[kolumny][wiersze], int n, int m)
  53. {
  54. int Wx;
  55. int Wy;
  56. for(int i =0; i< n; i++)
  57. {
  58. for(int j=0; j<m; j++)
  59. {
  60. if(lab[i][j] == 'W')
  61. {
  62. Wx=i;
  63. Wy=j;
  64. }
  65. }
  66. }
  67.  
  68.  
  69. int k=1;
  70. while (k)
  71. {
  72. wypiszLabirynt(lab, n, m);
  73.  
  74. int Xx;
  75. int Xy;
  76. for(int i=0; i < n; i++)
  77. {
  78. for(int j=0; j<m; j++)
  79. {
  80. if(lab[i][j] == 'X')
  81. {
  82. Xx=i;
  83. Xy=j;
  84. }
  85. }
  86. }
  87.  
  88. char klawisz;
  89. cin>>klawisz;
  90. switch(klawisz)
  91. {
  92. case 'a':
  93. if (Xy>0 && (lab[Xx][Xy-1] == 32 || lab[Xx][Xy-1] == 'W'))
  94. {
  95. lab[Xx][Xy] = 32;
  96. lab[Xx][Xy-1] = 88;
  97. }
  98. break;
  99.  
  100. case 'w':
  101. if (Xx>0 && (lab[Xx-1][Xy] == 32 || lab[Xx-1][Xy] == 'W'))
  102. {
  103. lab[Xx][Xy] = 32;
  104. lab[Xx-1][Xy] = 88;
  105. }
  106. break;
  107.  
  108. case 'd':
  109. if (Xy<m && ( lab[Xx][Xy+1] == 32 || lab[Xx][Xy+1] == 'W' ) )
  110. {
  111. lab[Xx][Xy] = 32;
  112. lab[Xx][Xy+1] = 88;
  113. }
  114. break;
  115.  
  116. case 's':
  117. if (Xx<n && (lab[Xx+1][Xy] == 32 || lab[Xx+1][Xy] == 'W'))
  118. {
  119. lab[Xx][Xy] = 32;
  120. lab[Xx+1][Xy] = 88;
  121. }
  122. break;
  123.  
  124. case 'q':
  125. k=0;
  126. system("pause");
  127. break;
  128.  
  129. default:
  130. k=0;
  131. cout << "Zly klawisz" << endl;
  132. break;
  133.  
  134. }
  135. if(Wx == Xx && Wy == Xy)
  136. k=0;
  137. cout << "koniec";
  138. }
  139.  
  140. }
  141.  
  142. int main()
  143. {
  144. char lab1[][wiersze] ={
  145.  
  146. {201,205,205,205,187,32,32,32,32,32}, //0
  147. {186,88,32,32,186,32,201,205,187,32}, //1
  148. {186,32,32,32,186,32,186,32,186,32}, //2
  149. {186,32,32,32,200,205,188,32,186,32}, //3
  150. {186,32,32,32,32,32,32,32,186,32}, //4
  151. {186,32,32,32,32,201,187,32,186,32}, //5
  152. {186,32,32,32,32,200,188,32,186,32}, //6
  153. {200,205,205,187,32,32,32,32,186,32}, //7
  154. {32,32,32,186,32,32,32,32,186,32}, //8
  155. {32,32,32,200,205,205,87,205,188,32} //9
  156. };
  157.  
  158. char lab2[][wiersze] ={
  159.  
  160. {32,32,32,32,32,32,32,32,32,32,201,87,187}, // 0
  161. {32,32,32,32,201,205,203,205,187,32,186,32,186}, //1
  162. {32,32,201,205,188,32,186,32,186,32,186,32,186}, //2
  163. {32,32,186,32,32,32,186,32,200,205,188,32,186}, //3
  164. {201,205,188,32,201,187,32,32,32,32,32,32,186}, //4
  165. {186,32,32,32,200,188,32,32,32,201,205,205,188}, //5
  166. {186,32,32,32,32,32,32,32,32,186,32,32,32}, //6
  167. {200,205,187,32,201,187,32,32,201,188,32,32,32}, //7
  168. {32,32,186,32,186,200,187,32,186,32,32,32,32}, //8
  169. {32,32,186,32,186,32,186,32,200,205,205,205,187}, //9
  170. {32,32,186,32,186,201,188,32,32,32,32,32,186}, //10
  171. {32,32,186,88,186,186,32,32,32,32,32,32,186}, //11
  172. {32,32,200,205,188,200,205,205,205,205,205,205,188}, //12
  173. };
  174.  
  175. char lab3[kolumny][wiersze] ={
  176.  
  177. {201,205,205,205,205,205,205,187,32,32,32,32,32,201,205,187}, //0
  178. {186,32,32,32,32,32,32,186,32,32,32,32,32,186,32,186}, //1
  179. {186,32,32,32,32,32,32,186,201,205,205,205,205,188,32,186}, //2
  180. {186,32,32,201,205,205,205,188,186,32,32,32,32,32,32,186}, //3
  181. {186,32,32,186,32,32,32,32,186,32,201,205,205,187,32,186}, //4
  182. {186,32,32,200,205,205,205,205,188,32,200,187,32,186,32,186}, //5
  183. {186,32,32,32,32,32,32,32,32,32,32,186,32,186,32,186}, //6
  184. {186,32,32,201,205,205,205,205,205,205,205,188,32,186,32,186}, //7
  185. {186,32,32,186,32,32,32,32,32,32,32,32,32,186,32,186}, //8
  186. {186,32,32,200,205,205,205,205,205,205,205,187,32,186,32,186}, //9
  187. {186,32,32,32,32,32,32,32,32,88,32,186,32,186,32,186}, //10
  188. {186,32,32,201,205,205,205,205,205,205,205,188,201,188,32,186}, //11
  189. {186,32,32,186,32,32,32,32,32,32,32,32,186,32,32,186}, //12
  190. {186,32,32,200,205,205,205,205,205,205,205,187,186,32,32,186}, //13
  191. {186,32,32,32,32,32,32,32,32,32,32,186,204,205,32,87}, //14
  192. {200,205,205,205,205,205,205,205,205,205,205,188,200,205,205,188} //15
  193. };
  194.  
  195.  
  196. {
  197.  
  198. int i=1;
  199. while(i)
  200. switch(menu())
  201. {
  202. case '1':
  203. poziom(lab1, 10, 10);
  204. break;
  205.  
  206. case '2':
  207. poziom(lab2, 13, 13);
  208. break;
  209.  
  210. case '3':
  211. poziom(lab3, 16, 16);
  212. break;
  213.  
  214. case 'q':
  215. i=0;
  216. return 0;
  217. break;
  218.  
  219. case '?':
  220. i=0;
  221. pomoc();
  222. break;
  223.  
  224. default:
  225. cout << "Zly klawisz" << endl;
  226. break;
  227. }
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement