Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 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=szerokosc+4, pktY=wysokosc/2+5, 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. //Panel górny
  27. wspolrzedne(5,3);
  28. cout<<char(201);
  29. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  30. cout<<char(187);
  31. for(int b=2;b<=wysokosc;b++){
  32. wspolrzedne(5,4);
  33. cout<<char(186);
  34. for(int c=3;c<=szerokosc;c++) cout<<" ";
  35. cout<<char(186)<<endl;
  36. }
  37.  
  38. //Œciana górna
  39. wspolrzedne(5,5);
  40. cout<<char(204);
  41. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  42. cout<<char(185)<<endl;
  43.  
  44. //Œciany boczne
  45. for(int b=2;b<=wysokosc;b++){
  46. wspolrzedne(5,4+b);
  47. cout<<char(186);
  48. for(int c=3;c<=szerokosc;c++) cout<<" ";
  49. cout<<char(186)<<endl;
  50. }
  51.  
  52. //Œciana dolna
  53. wspolrzedne(5,wysokosc+5);
  54. cout<<char(200);
  55. for(int a=3;a<=szerokosc;a++) cout<<char(205)<<char(205);
  56. cout<<char(188)<<endl;
  57. }
  58.  
  59. void ruch_punktu()
  60. {
  61. int kierunek_punktu;
  62.  
  63. srand(time(NULL));
  64. kierunek_punktu = rand()%4 + 1;
  65.  
  66. if(kierunek_punktu == 1){
  67. if(pktY > 4){
  68. pktY--;
  69. wspolrzedne(pktX,pktY);
  70. cout<<char(158);
  71. }
  72. else{
  73. pktY++;
  74. wspolrzedne(pktX,pktY);
  75. cout<<char(158);
  76. }
  77. }
  78. else if(kierunek_punktu == 2){
  79. if(pktY < (wysokosc - 1 + 5)){
  80. pktY++;
  81. wspolrzedne(pktX,pktY);
  82. cout<<char(158);
  83. }
  84. else{
  85. pktY--;
  86. wspolrzedne(pktX,pktY);
  87. cout<<char(158);
  88. }
  89. }
  90. else if(kierunek_punktu == 3){
  91. if(pktX > 6){
  92. pktX--;
  93. wspolrzedne(pktX,pktY);
  94. cout<<char(158);
  95. }
  96. else{
  97. pktX++;
  98. wspolrzedne(pktX,pktY);
  99. cout<<char(158);
  100. }
  101. }
  102. else if(kierunek_punktu == 4){
  103. if(pktX < (szerokosc*2 - 4 + 5)){
  104. pktX++;
  105. wspolrzedne(pktX,pktY);
  106. cout<<char(158);
  107. }
  108. else{
  109. pktX--;
  110. wspolrzedne(pktX,pktY);
  111. cout<<char(158);
  112. }
  113. }
  114.  
  115. }
  116.  
  117. void punkty()
  118. {
  119. if((ruchX == pktX) && (ruchY == pktY)){
  120. punkt++;
  121.  
  122. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
  123. srand(time(NULL));
  124. pktX=rand()%(szerokosc*2-4) + 6;
  125. pktY=rand()%(wysokosc-1) + 6;
  126. wspolrzedne(pktX,pktY);
  127. cout<<char(158);
  128. }
  129. }
  130.  
  131. void ruch()
  132. {
  133. if(c == 'w'){
  134. if(ruchY > 6) ruchY--;
  135. }
  136. else if(c == 's'){
  137. if(ruchY < (wysokosc - 1 + 5)) ruchY++;
  138. }
  139. else if(c == 'a'){
  140. if(ruchX > 6) ruchX--;
  141. }
  142. else if(c == 'd'){
  143. if(ruchX < (szerokosc*2 - 4 + 5)) ruchX++;
  144. }
  145. else{
  146. cout;
  147. }
  148. }
  149.  
  150. void gra()
  151. {
  152. srand(time(NULL));
  153. ruchX=rand()%(szerokosc*2-4) + 6;
  154. ruchY=rand()%(wysokosc-1) + 6;
  155. if((ruchX == pktX) && (ruchY == pktY)){
  156. ruchX--;
  157. ruchY--;
  158. }
  159.  
  160. system("cls");
  161. rysowanie_mapy();
  162.  
  163. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
  164. wspolrzedne(pktX,pktY);
  165. cout<<char(158);
  166.  
  167. while(c != char(13)){
  168. punkty();
  169. ruch_punktu();
  170. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
  171. wspolrzedne(ruchX,ruchY);
  172. cout<<char(254);
  173.  
  174. wspolrzedne(7, 4);
  175. cout<<"Ilosc zebranych punktow: "<<punkt;
  176. wspolrzedne(szerokosc*2-12,4);
  177. cout<<"Wyjdz = ENTER";
  178.  
  179. c=getch();
  180. wspolrzedne(ruchX,ruchY);
  181. cout<<" ";
  182. ruch();
  183. }
  184.  
  185. system("cls");
  186. }
  187.  
  188. void ustawienia()
  189. {
  190. string ustawienia_wybor;
  191. int wybor_szerokosci, wybor_wysokosci;
  192.  
  193. system("cls");
  194. cout<<"USTAWIENIA"<<endl;
  195. cout<<"1. Zmien rozmiar mapy"<<endl;
  196. cout<<"2. Wyjdz do menu"<<endl;
  197. cout<<"> ";
  198. cin>>ustawienia_wybor;
  199.  
  200. if(ustawienia_wybor == "1"){
  201. ustawienia_wybor = "";
  202. system("cls");
  203. cout<<"(Zakres 25-35) Zmien szerokosc z '"<<szerokosc<<"' na: ";
  204. cin>>wybor_szerokosci;
  205. cout<<"(Zakres 25-35) Zmien wysokosc z '"<<wysokosc<<"' na: ";
  206. cin>>wybor_wysokosci;
  207.  
  208. if((wybor_szerokosci>35 || wybor_szerokosci<25) || (wybor_wysokosci>35 || wybor_wysokosci<25)){
  209. cout<<endl<<"Zla wartosc!"<<endl;
  210. Sleep(500);
  211. system("cls");
  212. ustawienia();
  213. }
  214. else{
  215. szerokosc=wybor_szerokosci;
  216. wysokosc=wybor_wysokosci;
  217. }
  218.  
  219. cout<<endl<<"Pomyslnie zmieniono rozmiar mapy!"<<endl;
  220. Sleep(500);
  221. ustawienia();
  222. }
  223. else if(ustawienia_wybor == "2"){
  224. ustawienia_wybor = "";
  225. system("cls");
  226. }
  227. else{
  228. ustawienia_wybor = "";
  229. cout<<endl<<"Nie ma takiej opcji!"<<endl;
  230. Sleep(500);
  231. system("cls");
  232. ustawienia();
  233. }
  234. }
  235.  
  236. void instrukcja()
  237. {
  238. string instrukcja_wybor;
  239.  
  240. system("cls");
  241. cout<<"INSTRUKCJA"<<endl;
  242. cout<<"1. Ruch"<<endl;
  243. cout<<"2. Wyjdz"<<endl;
  244. cout<<"> ";
  245. cin>>instrukcja_wybor;
  246.  
  247. if(instrukcja_wybor == "1"){
  248. system("cls");
  249. cout<<"Wyjscie z gry do menu - 'ENTER'"<<endl;
  250. cout<<"Gora - 'W'"<<endl;
  251. cout<<"Dol - 'S'"<<endl;
  252. cout<<"Lewo - 'A'"<<endl;
  253. cout<<"Prawo - 'D'"<<endl;
  254. cout<<endl;
  255. cout<<"Kliknij wybrany przycisk aby wyjsc do menu"<<endl;
  256. getch();
  257. system("cls");
  258. }
  259. else if(instrukcja_wybor == "2"){
  260. instrukcja_wybor = "";
  261. system("cls");
  262. }
  263. else{
  264. instrukcja_wybor = "";
  265. cout<<endl<<"Nie ma takiej opcji!"<<endl;
  266. Sleep(500);
  267. system("cls");
  268. instrukcja();
  269. }
  270.  
  271. }
  272.  
  273. int menu()
  274. {
  275. for(;;){
  276. string menu_wybor;
  277.  
  278. c = char(178);
  279.  
  280. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),3);
  281. cout<<"Witaj graczu!"<<endl;
  282. cout<<"1. Gra"<<endl;
  283. cout<<"2. Instrukcja"<<endl;
  284. cout<<"3. Ustawienia"<<endl;
  285. cout<<"4. Wyjdz"<<endl;
  286. cout<<"> ";
  287. cin>>menu_wybor;
  288.  
  289. if(menu_wybor == "1") gra();
  290. else if(menu_wybor == "2") instrukcja();
  291. else if(menu_wybor == "3") ustawienia();
  292. else if(menu_wybor == "4"){
  293. system("cls");
  294. return 0;
  295. }
  296. else{
  297. cout<<endl<<"Nie ma takiej opcji!"<<endl;
  298. Sleep(500);
  299. system("cls");
  300. menu();
  301. }
  302. }
  303. }
  304.  
  305. int main()
  306. {
  307. menu();
  308.  
  309. return 0;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement