Guest User

Untitled

a guest
Apr 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <ctime>
  4. using namespace std;
  5. char array[40][30];
  6. void gotoxy(int x,int y){
  7. HANDLE hConsoleOutput;
  8. COORD Cursor_an_Pos={x-1,y-1};
  9. hConsoleOutput=GetStdHandle(STD_OUTPUT_HANDLE);
  10. SetConsoleCursorPosition(hConsoleOutput,Cursor_an_Pos);
  11. }
  12. void XoamanHinh(){
  13. HANDLE hOut;
  14. COORD Position;
  15. hOut=GetStdHandle(STD_OUTPUT_HANDLE);
  16. Position.X=0;
  17. Position.Y=0;
  18. SetConsoleCursorPosition(hOut,Position);
  19.  
  20. }
  21. void textcolor(int x){
  22. HANDLE mau;
  23. mau=GetStdHandle(STD_OUTPUT_HANDLE);
  24. SetConsoleTextAttribute(mau,x);
  25. }
  26. //void Ve_Hinh(int x,int y,int color,string str){
  27. // gotoxy(x,y);
  28. // textcolor(color);
  29. // cout<<str;
  30. //
  31. //}
  32. void DuongDua(){
  33. for (int i=0;i<25;i++){
  34. array[i][0]='|';
  35. array[i][29]='|';
  36. for (int j=1;j<29;j++){
  37. array[i][j]=' ';
  38. }
  39. }
  40. }
  41. int VeVat(int x,int y){
  42.  
  43. array[x-1][y]='X';//dau
  44.  
  45. //than
  46. array[x][y]='X';
  47. array[x][y-1]='X';
  48. array[x][y+1]='X';
  49.  
  50. //duoi
  51. array[x+1][y-1]='X';
  52. array[x+1][y-2]='X';
  53. array[x+1][y]='X';
  54. array[x+1][y+1]='X';
  55. array[x+1][y+2]='X';
  56. }
  57. void DiChuyenVat(int &x,int &y){
  58. if (GetAsyncKeyState(VK_LEFT)){
  59. if (y>3){
  60. array[x-1][y]=' ';//dau
  61.  
  62. //than
  63. array[x][y]=' ';
  64. array[x][y-1]=' ';
  65. array[x][y+1]=' ';
  66.  
  67. //duoi
  68. array[x+1][y-1]=' ';
  69. array[x+1][y-2]=' ';
  70. array[x+1][y]=' ';
  71. array[x+1][y+1]=' ';
  72. array[x+1][y+2]=' ';
  73. y--;
  74. VeVat(x,y);
  75. }
  76.  
  77. }
  78. if (GetAsyncKeyState(VK_RIGHT)){
  79. if (y<26){
  80. array[x-1][y]=' ';//dau
  81.  
  82. //than
  83. array[x][y]=' ';
  84. array[x][y-1]=' ';
  85. array[x][y+1]=' ';
  86.  
  87. //duoi
  88. array[x+1][y-1]=' ';
  89. array[x+1][y-2]=' ';
  90. array[x+1][y]=' ';
  91. array[x+1][y+1]=' ';
  92. array[x+1][y+2]=' ';
  93. y++;
  94. VeVat(x,y);
  95. }
  96. }
  97. if (GetAsyncKeyState(VK_UP)){
  98. if (x>1){
  99. array[x-1][y]=' ';//dau
  100.  
  101. //than
  102. array[x][y]=' ';
  103. array[x][y-1]=' ';
  104. array[x][y+1]=' ';
  105.  
  106. //duoi
  107. array[x+1][y-1]=' ';
  108. array[x+1][y-2]=' ';
  109. array[x+1][y]=' ';
  110. array[x+1][y+1]=' ';
  111. array[x+1][y+2]=' ';
  112. x--;
  113. VeVat(x,y);
  114. }
  115.  
  116. }
  117. if (GetAsyncKeyState(VK_DOWN)){
  118. if (x<23){
  119. array[x-1][y]=' ';//dau
  120.  
  121. //than
  122. array[x][y]=' ';
  123. array[x][y-1]=' ';
  124. array[x][y+1]=' ';
  125.  
  126. //duoi
  127. array[x+1][y-1]=' ';
  128. array[x+1][y-2]=' ';
  129. array[x+1][y]=' ';
  130. array[x+1][y+1]=' ';
  131. array[x+1][y+2]=' ';
  132. x++;
  133. VeVat(x,y);
  134. }
  135.  
  136. }
  137. }
  138. void VeChuongNgaiVat(int x1,int y1){
  139. array[x1][y1]='o';
  140. array[x1][y1+1]='o';
  141. array[x1][y1-1]='o';
  142. array[x1+1][y1]='o';
  143. }
  144. void ChuongNgaiVatChay(int x1,int y1){
  145. array[x1][y1]=' ';
  146. array[x1][y1+1]=' ';
  147. array[x1][y1-1]=' ';
  148. array[x1+1][y1]=' ';
  149. x1++;
  150. VeChuongNgaiVat(x1,y1);
  151.  
  152. }
  153. int ketQua_Tra_ve(int &x1,int &y1,int x,int y){
  154. if ((x1+2==x&&y1==y)||(x1==x+1&&y1==y+3)||(x1==x+1&&y1==y-3)||(x1==x&&y1==y+2)||(x1==x&&y1==y-2)){
  155. Sleep(1000);
  156. textcolor(114);
  157. gotoxy(35,25);
  158.  
  159. cout<<"GAMEOVER"<<endl<<endl;
  160. return 0;
  161. }
  162. if (x1==30){
  163. x1=2;
  164. y1=3+rand() % (26),x1=2;
  165. }
  166. }
  167.  
  168. void VeDuongdua(int x,int y){
  169. int i,j,score=0;
  170.  
  171. for (i=0;i<25;i++){
  172. cout<<"\t\t\t";
  173. for (j=0;j<30;j++){
  174. if (j==0||j==29) {
  175. textcolor(134);
  176. cout<<array[i][j];
  177. textcolor(7);
  178. }
  179. else if (array[i][j]=='X'){
  180. textcolor(124);
  181. cout<<array[i][j];
  182. }
  183. else if(array[i][j]=='o'){
  184. textcolor(112);
  185. cout<<array[i][j];
  186. textcolor(119);
  187. }
  188. else if (array[i][j]=='0'){
  189. textcolor(112);
  190. cout<<array[i][j];
  191. textcolor(119);
  192. }
  193. else{
  194.  
  195. textcolor(119);
  196. cout<<array[i][j];
  197. }
  198. }
  199. cout<<endl;
  200. score++;
  201. //return score;
  202. }
  203. }
  204. int playAgain(){
  205. cout<<"Do you want play again(1=yes/2=no): ";
  206. int answer;
  207.  
  208. cin>>answer;
  209.  
  210. if (answer==1) {
  211. XoamanHinh();
  212. return 1;;
  213. }
  214. else return 0;
  215. }
  216. int Score(int score){
  217. gotoxy(35,13);
  218. cout<<"Score: "<<score/2;
  219. for (int k=0;k<13;k++){
  220. cout<<endl;
  221. }
  222. textcolor(7);
  223. }
  224. void intro(){
  225. textcolor(7);
  226. cout<<"EVERWING"<<endl;
  227. Sleep(1000);
  228. XoamanHinh();
  229. }
  230. int Skill(int &d1,int &d2){
  231. array[d1][d2]='0';
  232. }
  233. int Ban(int d1,int d2){
  234. array[d1][d2]=' ';
  235. d1=d1-2;
  236. Skill(d1,d2);
  237. }
  238. int AnDiem(int x1,int y1,int d1,int d2){
  239. if ((x1+1==d1&&y1==d2)||(x1==d1&&y1-1==d2)||(x1=d1&&y1+1==d2)){
  240. array[x1][y1]=' ';
  241. array[x1][y1+1]=' ';
  242. array[x1][y1-1]=' ';
  243. array[x1+1][y1]=' ';
  244. return 1;
  245. }
  246. }
  247. int text(int &x1,int &y1,int x,int y,int score){
  248. if (ketQua_Tra_ve(x1,y1,x,y)==0) {
  249. Score(score);
  250. score=0;
  251. if (playAgain()==1){
  252. return 1;
  253.  
  254. }
  255. else {
  256. // gotoxy(34,28);
  257. // cout<<"BYE BYE!!!";
  258. return 0;
  259. }
  260.  
  261. }
  262. }
  263. int main(){
  264. intro();
  265. int n=0,score=0;
  266. int x=18,y=15;
  267. srand(time(0));
  268. int y1=3+rand() % (26),x1=2;
  269. //int y2=3+rand() % (26),x2=2;
  270. int d1,d2;
  271. bool check=false;
  272. do{
  273. d1=x-1;
  274. d2=y;
  275. while (true){
  276. VeDuongdua(x,y);
  277. XoamanHinh();
  278. VeVat(x,y);
  279. DiChuyenVat(x,y);
  280. ChuongNgaiVatChay(x1,y1);
  281. x1++;
  282. // ChuongNgaiVatChay(x2,y2);
  283. // x2++;
  284. score++;
  285.  
  286.  
  287. Skill(d1,d2);
  288. if(d1==1){
  289. array[d1][d2]=' ';
  290. d1=x-1;
  291. d2=y;
  292. }
  293. Ban(d1,d2);
  294. d1=d1-2;
  295.  
  296. // AnDiem(x1,y1,d1,d2);
  297. // AnDiem(x2,y2,d1,d2);
  298.  
  299. if (AnDiem(x1,y1,d1,d2)==1){
  300. x1=2;
  301. y1=7;
  302. array[x1][y1]=' ';
  303. array[x1][y1+1]=' ';
  304. array[x1][y1-1]=' ';
  305. array[x1+1][y1]=' ';
  306. score=score+10;
  307. }
  308. // if (AnDiem(x2,y2,d1,d2)==1){
  309. // x2=2;
  310. // y2=7;
  311. // array[x1][y1]=' ';
  312. // array[x1][y1+1]=' ';
  313. // array[x1][y1-1]=' ';
  314. // array[x1+1][y1]=' ';
  315. // score=score+10;
  316. // }
  317.  
  318.  
  319. // text(x1,y1,x,y,score);
  320. // text(x2,y2,x,y,score);
  321. // if (text(x1,y1,x,y,score)==1||text(x2,y2,x,y,score)==1){
  322. // continue;
  323. // }
  324. // if (text(x1,y1,x,y,score)==0||text(x2,y2,x,y,score)==0){
  325. // gotoxy(34,28);
  326. // cout<<"BYE BYE!!!";
  327. // break;
  328. // }
  329.  
  330. if (ketQua_Tra_ve(x1,y1,x,y)==0) {
  331. Score(score);
  332. score=0;
  333.  
  334. if (playAgain()==1){
  335. continue;
  336.  
  337. }
  338.  
  339. else {
  340. gotoxy(34,28);
  341. cout<<"BYE BYE!!!";break;
  342. }
  343.  
  344. }
  345. if (n>20) n=0;
  346. }
  347. }while(check);
  348. return 0;
  349. }
Add Comment
Please, Sign In to add comment