fork(2) download
  1. #include<windows.h>
  2. #include<iostream>
  3. #include <conio.h>
  4. #include<string>
  5. #define resizeConsole rc
  6. #define it int
  7. #define fla 200 // toc do ran
  8. #define m 6 // hien thi mau thuc an
  9. #define colorht 10// hien thi mau ten nguoi choi va diem
  10. #define mauran 1// hien thi mau ran
  11. #define maukhung 4 // hien thi mau khung
  12. using namespace std;
  13. /*các hàm lam game có san copy tren mang*/
  14. void resizeConsole(it width, it height)
  15. {
  16. HWND console = GetConsoleWindow();
  17. RECT r;
  18. GetWindowRect(console, &r);
  19. MoveWindow(console, r.left, r.top, width, height, TRUE);
  20. }
  21. void textcolor(it x) // ham mau sac
  22. {
  23. HANDLE mau;
  24. mau = GetStdHandle(STD_OUTPUT_HANDLE);
  25. SetConsoleTextAttribute(mau, x);
  26. }
  27. void gotoxy(it x, it y) // ham dich chuyen con tro
  28. {
  29. HANDLE hConsoleOutput;
  30. COORD Cursor_an_Pos = { x - 1,y - 1 };
  31. hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  32. SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
  33. }
  34. /* CODE BY : VO VAN NGUYEN */
  35. /* huong doi tuong */
  36. it kt;
  37. it diem = 1;
  38. class khunghinh
  39. {
  40. private:
  41. it map[200][200];
  42. it x, y;
  43. public:
  44. khunghinh()
  45. {
  46. x = 30;
  47. y = 50;
  48. }
  49. void taokhung()
  50. {
  51. it i, j;
  52. for (i = 1; i <= x; i++)
  53. {
  54. for (j = 1; j <= y; j++)
  55. {
  56. if (i == 1 || i == x || j == 1 || j == y)
  57. map[i][j] = 3;
  58. else
  59. map[i][j] = 0;
  60.  
  61. }
  62. }
  63. }
  64. void hienthikhung()
  65. {
  66. it i, j;
  67. string ht;
  68. gotoxy(60, 10);
  69. textcolor(colorht);
  70. cout << "NGUOI CHOI :";
  71. getline(cin, ht);
  72. gotoxy(60, 11);
  73. cout << "DIEM: ";
  74. gotoxy(68, 11);
  75. cout << diem;
  76. gotoxy(60, 14);
  77. cout << "DIEU KHIEN BANG: CAC PHIM MUI TEN" ;
  78. gotoxy(60, 18);
  79. cout << "**********CODE BY VO VAN NGUYEN**********";
  80. gotoxy(1, 1);
  81. for (j = 1; j <= y; j++)
  82. {
  83. textcolor(maukhung);
  84. cout << "=";
  85. }
  86. cout << endl;
  87. for (i = 2; i < x; i++)
  88. {
  89. for (j = 1; j <= y; j++)
  90. {
  91. if (map[i][j] == 3)
  92. cout << "#";
  93. else
  94. cout << ' ';
  95. }
  96. cout << endl;
  97. }
  98. for (j = 1; j <= y; j++)
  99. cout << "=";
  100. }
  101. void truyen(it x1, it y1, it v)
  102. {
  103. map[x1][y1] = v;
  104. }
  105. it getvt(it x2, it y2)
  106. {
  107. return map[x2][y2];
  108. }
  109. void test()
  110. {
  111. for (it i = 1; i <= x; i++)
  112. {
  113. for (it j = 1; j <= y; j++)
  114. cout << map[i][j];
  115. cout << endl;
  116. }
  117. }
  118. void taothucan()
  119. {
  120. it r;
  121. do
  122. {
  123. it tx = rand() % 28 + 3;
  124. it ty = rand() % 48 + 3;
  125. if (getvt(tx, ty) == 0)
  126. {
  127. truyen(tx, ty, 2);
  128. textcolor(m);
  129. gotoxy(ty, tx);
  130. cout << "$";
  131. kt = 1;
  132. r = 0;
  133. }
  134. else
  135. r = 1;
  136. } while (r == 1);
  137. }
  138. };
  139. class Stack
  140. {
  141. private:
  142. pair<it, it> kk[1500];
  143. int dau;
  144. public:
  145. Stack()
  146. {
  147. dau = 0;
  148. }
  149. void themdau(it x, it y)
  150. {
  151. kk[dau].first = x;
  152. kk[dau].second = y;
  153. dau++;
  154. }
  155. void xoa()
  156. {
  157. for (int i = 0; i < dau; i++)
  158. {
  159. kk[i].first = kk[i + 1].first;
  160. kk[i].second = kk[i + 1].second;
  161. }
  162. dau--;
  163. }
  164.  
  165. it getxc()
  166. {
  167. return kk[0].first;
  168. }
  169. it getyc()
  170. {
  171. return kk[0].second;
  172. }
  173.  
  174. };
  175. class conran : public khunghinh
  176. {
  177. private:
  178. it xd;
  179. it yd;
  180. Stack ran;
  181. public:
  182. conran()
  183. {
  184. xd = 15;
  185. yd = 25;
  186. }
  187.  
  188. void vedot(it x, it y) // ve dôt dau
  189. {
  190. gotoxy(y, x);
  191. textcolor(mauran);
  192. cout << "*";
  193.  
  194. }
  195. void xoadot(it x, it y) //xóa dot cuoi
  196. {
  197. gotoxy(y, x);
  198. cout << " ";
  199. truyen(x, y, 0);
  200.  
  201. }
  202. void khoitaoran()
  203. {
  204. conran();
  205. vedot(xd, yd); // dau
  206. ran.themdau(xd, yd);
  207. truyen(xd, yd, 1);
  208.  
  209. taothucan();
  210.  
  211. }
  212. int len()
  213. {
  214. Sleep(fla);
  215. if (kt == 0)
  216. taothucan();
  217. xd--;
  218. ran.themdau(xd, yd);
  219. vedot(xd, yd);
  220. if (getvt(xd, yd) == 2)
  221. {
  222. kt = 0;
  223. cout << "\a";
  224. diem++;
  225. textcolor(colorht);
  226. gotoxy(68, 11);
  227. cout << diem;
  228. }
  229. else if (getvt(xd, yd) == 3)
  230. {
  231. gotoxy(15, 25);
  232. textcolor(colorht);
  233. cout << "________________THANKS YOU______________" << endl;
  234. cout << "________________DIEM CUA BAN : " << diem << " __________";
  235. exit(0);
  236. }
  237. else
  238. {
  239. xoadot(ran.getxc(), ran.getyc());
  240. ran.xoa();
  241. }
  242. truyen(xd, yd, 1);
  243. }
  244. int xuong()
  245. {
  246. Sleep(fla);
  247. if (kt == 0)
  248. taothucan();
  249. xd++;
  250. ran.themdau(xd, yd);
  251. vedot(xd, yd);
  252. if (getvt(xd, yd) == 2)
  253. {
  254.  
  255. kt = 0;
  256. cout << "\a";
  257. diem++;
  258. textcolor(colorht);
  259. gotoxy(68, 11);
  260. cout << diem;
  261.  
  262. }
  263. else if (getvt(xd, yd) == 3)
  264. {
  265. gotoxy(15, 25);
  266. textcolor(colorht);
  267. cout << "________________THANKS YOU______________" << endl;
  268. cout << "________________DIEM CUA BAN : " << diem << " ___________";
  269. exit(0);
  270. }
  271. else
  272. {
  273. xoadot(ran.getxc(), ran.getyc());
  274. ran.xoa();
  275. }
  276. truyen(xd, yd, 1);
  277. }
  278. int trai()
  279. {
  280.  
  281. Sleep(fla);
  282. if (kt == 0)
  283. taothucan();
  284. yd--;
  285. ran.themdau(xd, yd);
  286. vedot(xd, yd);
  287. if (getvt(xd, yd) == 2)
  288. {
  289.  
  290. kt = 0;
  291. cout << "\a";
  292. diem++;
  293. textcolor(colorht);
  294. gotoxy(68, 11);
  295. cout << diem;
  296. }
  297. else if (getvt(xd, yd) == 3)
  298. {
  299. gotoxy(15, 25);
  300. textcolor(colorht);
  301. cout << "________________THANKS YOU______________" << endl;
  302. cout << "__________________DIEM CUA BAN : " << diem << "__________";
  303. exit(0);
  304. }
  305. else
  306. {
  307. xoadot(ran.getxc(), ran.getyc());
  308. ran.xoa();
  309. }
  310. truyen(xd, yd, 1);
  311. }
  312. int phai()
  313. {
  314. Sleep(fla);
  315. if (kt == 0)
  316. taothucan();
  317. yd++;
  318. ran.themdau(xd, yd);
  319. vedot(xd, yd);
  320. if (getvt(xd, yd) == 2)
  321. {
  322. cout << "\a";
  323. kt = 0;
  324. diem++;
  325. textcolor(colorht);
  326. gotoxy(68, 11);
  327. cout << diem;
  328. }
  329. else if (getvt(xd, yd) == 3)
  330. {
  331. gotoxy(15, 25);
  332. textcolor(colorht);
  333. cout << "________________THANKS YOU______________" << endl;
  334. cout << "________________DIEM CUA BAN : " << diem << " ___________";
  335. exit(0);
  336. }
  337. else
  338. {
  339. xoadot(ran.getxc(), ran.getyc());
  340. ran.xoa();
  341. }
  342. truyen(xd, yd, 1);
  343. }
  344. };
  345. int main()
  346. {
  347. rc(800, 600); // chinh console
  348. conran a;
  349. a.taokhung();
  350. a.hienthikhung();
  351. a.khoitaoran();
  352. while (1)
  353. {
  354. if (_kbhit() != 0)
  355. {
  356. it l = _getch();
  357. switch (l)
  358. {
  359. case 72:
  360. while (_kbhit() == 0)
  361. {
  362. a.len();
  363. }
  364. break;
  365. case 80:
  366. while (_kbhit() == 0)
  367. {
  368. a.xuong();
  369. }
  370. break;
  371. case 75:
  372. while (_kbhit() == 0)
  373. {
  374. a.trai();
  375. }
  376. break;
  377. case 77:
  378. while (_kbhit() == 0)
  379. {
  380. a.phai();
  381. }
  382. break;
  383. case 32:
  384. system("cls");
  385. a.test();
  386. break;
  387. }
  388. }
  389. }
  390. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:9: fatal error: windows.h: No such file or directory
 #include<windows.h>
         ^~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty