Advertisement
Guest User

Untitled

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