Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <windows.h>
  4. #include <time.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <fstream>
  9.  
  10. using namespace std;
  11.  
  12. int szerokosc=25, wysokosc=25;
  13. int ruchX, ruchY, pktX, pktY, punkt;
  14. char c;
  15.  
  16. void wspolrzedne(int x,int y)
  17. {
  18. COORD coord;
  19. coord.X=x;
  20. coord.Y=y;
  21. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  22. }
  23.  
  24. void rysowanie_mapy()
  25. {
  26. wspolrzedne(5,3);
  27. cout<<char(201);
  28. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  29. cout<<char(187);
  30. for(int b=2;b<=wysokosc;b++){
  31. wspolrzedne(5,4);
  32. cout<<char(186);
  33. for(int c=3;c<=szerokosc;c++) cout<<" ";
  34. cout<<char(186)<<endl;
  35. }
  36.  
  37. wspolrzedne(5,5);
  38. cout<<char(204);
  39. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  40. cout<<char(185)<<endl;
  41.  
  42. for(int b=2;b<=wysokosc;b++){
  43. wspolrzedne(5,4+b);
  44. cout<<char(186);
  45. for(int c=3;c<=szerokosc;c++) cout<<" ";
  46. cout<<char(186)<<endl;
  47. }
  48.  
  49. wspolrzedne(5,wysokosc+5);
  50. cout<<char(200);
  51. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  52. cout<<char(188)<<endl;
  53. }
  54.  
  55. void pierwszy_punkt()
  56. {
  57. pktX=szerokosc+4;
  58. pktY=wysokosc/2+5;
  59. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
  60. wspolrzedne(pktX,pktY);
  61. cout<<char(158);
  62. }
  63.  
  64. void punkty()
  65. {
  66. if((ruchX == pktX) && (ruchY == pktY)){
  67. punkt++;
  68.  
  69. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
  70. srand(time(NULL));
  71. pktX=rand()%(szerokosc*2-4) + 6;
  72. pktY=rand()%(wysokosc-1) + 6;
  73. wspolrzedne(pktX,pktY);
  74. cout<<char(158);
  75. }
  76. }
  77.  
  78. void ruch()
  79. {
  80. if(c == 'w'){
  81. if(ruchY>6) ruchY--;
  82. }
  83. else if(c == 's'){
  84. if(ruchY<(wysokosc - 1 + 5)) ruchY++;
  85. }
  86. else if(c == 'a'){
  87. if(ruchX>6) ruchX--;
  88. }
  89. else if(c == 'd'){
  90. if(ruchX<(szerokosc*2 - 4 + 5)) ruchX++;
  91. }
  92. else{
  93. cout;
  94. }
  95. }
  96.  
  97. void gra()
  98. {
  99. srand(time(NULL));
  100. ruchX=rand()%(szerokosc*2-4) + 6;
  101. ruchY=rand()%(wysokosc-1) + 6;
  102.  
  103. system("cls");
  104. rysowanie_mapy();
  105. pierwszy_punkt();
  106.  
  107. while(c != char(13)){
  108. punkty();
  109. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
  110. wspolrzedne(ruchX,ruchY);
  111. cout<<char(254);
  112.  
  113. wspolrzedne(7, 4);
  114. cout<<"Ilosc zebranych punktow: "<<punkt;
  115. wspolrzedne(szerokosc*2-12,4);
  116. cout<<"Wyjdz = ENTER";
  117.  
  118. c=getch();
  119. wspolrzedne(ruchX,ruchY);
  120. cout<<" ";
  121. ruch();
  122. }
  123.  
  124. system("cls");
  125. }
  126.  
  127. void ustawienia()
  128. {
  129. string ustawienia_wybor;
  130. int wybor_szerokosci, wybor_wysokosci;
  131.  
  132. system("cls");
  133. cout<<"USTAWIENIA"<<endl;
  134. cout<<"1. Zmien rozmiar mapy"<<endl;
  135. cout<<"2. Wyjdz do menu"<<endl;
  136. cout<<"> ";
  137. cin>>ustawienia_wybor;
  138.  
  139. if(ustawienia_wybor == "1"){
  140. ustawienia_wybor = "";
  141. system("cls");
  142. cout<<"(Zakres 15-30) Zmien szerokosc z '"<<szerokosc<<"' na: ";
  143. cin>>wybor_szerokosci;
  144. cout<<"(Zakres 15-30) Zmien wysokosc z '"<<wysokosc<<"' na: ";
  145. cin>>wybor_wysokosci;
  146.  
  147. if((wybor_szerokosci>30 || wybor_szerokosci<15) || (wybor_wysokosci>30 || wybor_wysokosci<15)){
  148. cout<<endl<<"Zla wartosc!"<<endl;
  149. Sleep(500);
  150. system("cls");
  151. ustawienia();
  152. }
  153. else{
  154. szerokosc=wybor_szerokosci;
  155. wysokosc=wybor_wysokosci;
  156. }
  157.  
  158. cout<<endl<<"Pomyslnie zmieniono rozmiar mapy!"<<endl;
  159. Sleep(500);
  160. ustawienia();
  161. }
  162. if(ustawienia_wybor == "2"){
  163. system("cls");
  164. }
  165. else{
  166. ustawienia_wybor = "";
  167. cout<<endl<<"Nie ma takiej opcji!"<<endl;
  168. Sleep(500);
  169. system("cls");
  170. ustawienia();
  171. }
  172. }
  173.  
  174. int menu()
  175. {
  176. for(;;){
  177. string menu_wybor;
  178.  
  179. c = char(178);
  180.  
  181. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),3);
  182. cout<<"Witaj graczu!"<<endl;
  183. cout<<"1. Gra"<<endl;
  184. cout<<"2. Ustawienia"<<endl;
  185. cout<<"3. Wyjdz"<<endl;
  186. cout<<"> ";
  187. cin>>menu_wybor;
  188.  
  189. if(menu_wybor == "1") gra();
  190. else if(menu_wybor == "2") ustawienia();
  191. else if(menu_wybor == "3"){
  192. system("cls");
  193. return 0;
  194. }
  195. else{
  196. cout<<endl<<"Nie ma takiej opcji!"<<endl;
  197. Sleep(500);
  198. system("cls");
  199. menu();
  200. }
  201. }
  202. }
  203.  
  204. int main()
  205. {
  206. menu();
  207.  
  208. return 0;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement