tanke_huangleleView.cpp
上传用户:jindun001
上传日期:2021-02-02
资源大小:13780k
文件大小:18k
源码类别:

射击游戏

开发平台:

Visual C++

  1. // tanke_huangleleView.cpp : implementation of the CTanke_huangleleView class
  2. //
  3. #include "stdafx.h"
  4. #include "tanke_huanglele.h"
  5. #include "tanke_huangleleDoc.h"
  6. #include "tanke_huangleleView.h"
  7. #include "Explanation.h"
  8. #pragma comment(lib,"ReadPicture_dll.lib")
  9. extern "C" _declspec(dllexport)void ReadFilePicture(int *arr ,int point ,int Wide,int High);
  10. #pragma comment(lib,"PutBullet.lib")
  11. extern "C" _declspec(dllexport)void PutFileBullet(int *arr ,int point );
  12. #pragma comment(lib,"Putexplosion_dll.lib")
  13. extern "C" _declspec(dllexport)void PutFileexplosion(int *arr ,int point );
  14. #pragma comment(lib,"Putfileborn_dll.lib")
  15. extern "C" _declspec(dllexport)void PutFileborn(int *arr ,int point );
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. int a[300][300];
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CTanke_huangleleView
  24. IMPLEMENT_DYNCREATE(CTanke_huangleleView, CView)
  25. BEGIN_MESSAGE_MAP(CTanke_huangleleView, CView)
  26. //{{AFX_MSG_MAP(CTanke_huangleleView)
  27. ON_COMMAND(IDC_START, OnStart)
  28. ON_COMMAND(IDC_STOP, OnStop)
  29. ON_WM_KEYDOWN()
  30. ON_WM_TIMER()
  31. ON_WM_LBUTTONDOWN()
  32. //}}AFX_MSG_MAP
  33. // Standard printing commands
  34. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  35. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  36. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CTanke_huangleleView construction/destruction
  40. void PutPicture(int flag,int countx,int county,int num,CDC* pDC)
  41. {
  42. int kx1=sizetangke*(countx-1);
  43. int kx2=sizetangke*countx;
  44. int ky1=sizetangke*(county-1);
  45. int ky2=sizetangke*county;
  46. if(1==flag)
  47. {
  48. for(int i=kx1;i<kx2;i++)
  49. for(int j=ky1;j<ky2;j++)
  50. {
  51.  if(playerfile[i][j]!=RGB(0,0,0))
  52.          pDC->SetPixel(playerx+(i-kx1),playery+(j-ky1),playerfile[i][j]);
  53. }
  54. }
  55. if(2==flag)
  56. {
  57. if(1==county)
  58. emeryy[num]-=17;
  59. else if(2==county)
  60. emeryx[num]+=17;
  61. else if(3==county)
  62. emeryy[num]+=17;
  63. else if(4==county)
  64. emeryx[num]-=17;
  65. if(emeryy[num]>630)
  66. emeryy[num]=630;
  67. if(emeryy[num]<20)
  68. emeryy[num]=20;
  69. if(emeryx[num]>770)
  70. emeryx[num]=770;
  71. if(emeryx[num]<120)
  72. emeryx[num]=120;
  73. for(int i=kx1;i<kx2;i++)
  74. for(int j=ky1;j<ky2;j++)
  75. {
  76.  if(emeryfile[i][j]!=RGB(0,0,0))
  77.          pDC->SetPixel(emeryx[num]+(i-kx1),emeryy[num]+(j-ky1),emeryfile[i][j]);
  78. }
  79. }
  80. if(3==flag)
  81. {
  82. for(int i=0;i<32;i++)
  83. for(int j=0;j<32;j++)
  84. {
  85. if(bornarr1[i][j]!=RGB(255,255,255))
  86.             pDC->SetPixel(playerx+i,playery+i,bornarr1[i][j]);
  87. }
  88. }
  89. if(4==flag)
  90. {
  91. for(int i=0;i<32;i++)
  92. for(int j=0;j<32;j++)
  93. {
  94. if(bornarr2[i][j]!=RGB(255,255,255))
  95.             pDC->SetPixel(playerx+i,playery+j,bornarr2[i][j]);
  96. }
  97. }
  98. }
  99. void PutBullet(int mark,int num,CDC* pDC)
  100. {
  101. if(1==mark)
  102. {
  103. if(playerbulletx<775 && playerbulletx>145 && playerbullety>75 && playerbullety<575)
  104. {
  105. for(int i=0;i<7;i++)
  106. for(int j=0;j<7;j++)
  107. {
  108. if(playerbulletfile[i][j]!=RGB(255,255,255))
  109. pDC->SetPixel(playerbulletx+i,playerbullety+j,playerbulletfile[i][j]);
  110. }
  111. }
  112. }
  113. if(2==mark)
  114. {
  115. if(emerybulletx[num]<775 && emerybulletx[num]>145 && emerybullety[num]>75 && emerybullety[num]<575)
  116. {
  117. for(int i=0;i<7;i++)
  118. for(int j=0;j<7;j++)
  119. {
  120. if(emerybulletfile[i][j]!=RGB(255,255,255))
  121. pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]+j,emerybulletfile[i][j]);
  122. }
  123. }
  124. }
  125. }
  126. void Putexplosion(int mark,int point,int num,CDC*pDC)
  127. {
  128. if(1==mark)
  129. {
  130.     for(int i=0;i<28;i++)
  131. for(int j=0;j<28;j++)
  132. {
  133. //if(playerbulletfile[i][j]!=RGB(4,4,4))
  134. pDC->SetPixel(playerbulletx+i,playerbullety-13+j,explosionarr1[i][j]);
  135. }
  136. }
  137. if(3==mark)
  138. {
  139.     for(int i=0;i<28;i++)
  140. for(int j=0;j<28;j++)
  141. {
  142. //if(explosionarr1[i][j]!=RGB(4,4,4))
  143. pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-13+j,explosionarr1[i][j]);
  144. }
  145. }
  146. if(2==mark)
  147. {
  148.     for(int i=0;i<64;i++)
  149. for(int j=0;j<64;j++)
  150. {
  151. //if(explosionarr2[i][j]!=RGB(4,4,4))
  152.     if(1==point)
  153. {
  154.     pDC->SetPixel(playerbulletx-32+i,playerbullety+j,explosionarr2[i][j]);
  155. }
  156.     if(2==point)
  157. {
  158.      pDC->SetPixel(playerbulletx+i,playerbullety-32+j,explosionarr2[i][j]);
  159. }
  160.      if(3==point)
  161. {
  162.      pDC->SetPixel(playerbulletx-32+i,playerbullety-14+j,explosionarr2[i][j]);
  163. }
  164.      if(4==point)
  165. {
  166.      pDC->SetPixel(playerbulletx+i,playerbullety-32+j,explosionarr2[i][j]);
  167. }
  168. }
  169. }
  170. if(4==mark)
  171. {
  172.     for(int i=0;i<64;i++)
  173. for(int j=0;j<64;j++)
  174. {
  175. //if(playerbulletfile[i][j]!=RGB(4,4,4))
  176.     if(1==point)
  177. {
  178.     pDC->SetPixel(emerybulletx[num]-32+i,emerybullety[num]+j,explosionarr2[i][j]);
  179. }
  180.     if(2==point)
  181. {
  182.      pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-32+j,explosionarr2[i][j]);
  183. }
  184.      if(3==point)
  185. {
  186.      pDC->SetPixel(emerybulletx[num]-32+i,emerybullety[num]-14+j,explosionarr2[i][j]);
  187. }
  188.      if(4==point)
  189. {
  190.      pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-32+j,explosionarr2[i][j]);
  191. }
  192. born=6;
  193. }
  194. }
  195. }
  196. CTanke_huangleleView::CTanke_huangleleView()
  197. {
  198. // TODO: add construction code here
  199.     ReadFilePicture(playerfile[0],player,112,112);
  200. ReadFilePicture(emeryfile[0],emery,112,112);
  201. PutFileBullet(playerbulletfile[0] ,player );
  202. PutFileBullet(emerybulletfile[0] ,emery );
  203. PutFileexplosion(explosionarr1[0] ,player);
  204. PutFileexplosion(explosionarr2[0] ,emery);
  205. PutFileborn(bornarr1[0] , player);
  206. PutFileborn(bornarr2[0] ,emery);
  207. emerynum=MAXNUM;
  208. playerx=506;
  209. playery=336;
  210. playertankelive=3;
  211. born=0;
  212. countx=2;
  213. county=1;
  214. play=2;
  215. playerbulletx=0;
  216. playerbullety=0;
  217. cannon=0;
  218. playerbulletrun=0;
  219. playerbulletdirection=0;
  220. //CRect rc(playerx-28,playery-28,playerx+28,playery+28);
  221. CRect rc(playerx,playery,playerx+28,playery+28);
  222. for(int i=0;i<MAXNUM;i++)
  223. {
  224. srand(i*time(0)+3);
  225. emeryx[i]=rand()%800;
  226. emeryy[i]=rand()%600;
  227. if(emeryy[i]>500)
  228. emeryy[i]=500;
  229. if(emeryy[i]<120)
  230. emeryy[i]=120;
  231. emerydirection[i]=rand()%4+1;
  232. emerytankelive[i]=1;
  233. // CRect remery[i](emeryx[i],emeryy[i],emeryx[i]+28,emeryy[i]+28);
  234. }
  235. }
  236. CTanke_huangleleView::~CTanke_huangleleView()
  237. {
  238. }
  239. BOOL CTanke_huangleleView::PreCreateWindow(CREATESTRUCT& cs)
  240. {
  241. // TODO: Modify the Window class or styles here by modifying
  242. //  the CREATESTRUCT cs
  243. return CView::PreCreateWindow(cs);
  244. }
  245. /////////////////////////////////////////////////////////////////////////////
  246. // CTanke_huangleleView drawing
  247. void CTanke_huangleleView::OnDraw(CDC* pDC)
  248. {
  249. CTanke_huangleleDoc* pDoc = GetDocument();
  250. ASSERT_VALID(pDoc);
  251. // TODO: add draw code for native data here
  252. pDC->Rectangle(CRect(120,50,800,600));
  253. CBitmap bm3;
  254. bm3.LoadBitmap(IDB_BITMAP3);
  255. CDC dcMem3;
  256. dcMem3.CreateCompatibleDC(pDC);
  257.     CBitmap*pOldbmp3=dcMem3.SelectObject(&bm3);
  258.     pDC->BitBlt(0,0,640,40,&dcMem3,0,0,SRCCOPY);
  259. pDC->BitBlt(640,0,800,40,&dcMem3,0,0,SRCCOPY);
  260.     pDC->BitBlt(0,600,640,1080,&dcMem3,0,0,SRCCOPY);
  261. pDC->BitBlt(640,600,800,1080,&dcMem3,0,0,SRCCOPY);
  262.     pDC->BitBlt(0,0,120,480,&dcMem3,0,0,SRCCOPY);
  263. pDC->BitBlt(0,480,120,960,&dcMem3,0,0,SRCCOPY);
  264.     pDC->BitBlt(800,0,1280,480,&dcMem3,0,0,SRCCOPY);
  265. pDC->BitBlt(800,480,1280,960,&dcMem3,0,0,SRCCOPY);
  266. dcMem3.SelectObject(pOldbmp3);
  267. CBitmap bm;
  268. bm.LoadBitmap(IDB_BITMAP1);
  269. CDC dcMem;
  270. dcMem.CreateCompatibleDC(pDC);
  271.     CBitmap*pOldbmp=dcMem.SelectObject(&bm);
  272.     pDC->BitBlt(88,18,120,592,&dcMem,0,0,SRCCOPY);
  273. pDC->BitBlt(800,18,832,592,&dcMem,0,0,SRCCOPY);
  274. dcMem.SelectObject(pOldbmp);
  275. CBitmap bm1;
  276. bm1.LoadBitmap(IDB_BITMAP2);
  277. CDC dcMem1;
  278. dcMem1.CreateCompatibleDC(pDC);
  279.     CBitmap*pOldbmp1=dcMem1.SelectObject(&bm1);
  280.     pDC->BitBlt(120,18,680,50,&dcMem1,0,0,SRCCOPY);
  281. pDC->BitBlt(120,600,680,632,&dcMem1,0,0,SRCCOPY);
  282. dcMem.SelectObject(pOldbmp1);
  283. CBitmap bm6;
  284. bm6.LoadBitmap(IDB_BITMAP6);
  285. CDC dcMem6;
  286. dcMem6.CreateCompatibleDC(pDC);
  287.     CBitmap*pOldbmp6=dcMem6.SelectObject(&bm6);
  288.     pDC->BitBlt(850,100,950,150,&dcMem6,0,0,SRCCOPY);
  289. dcMem.SelectObject(pOldbmp6);
  290. CBitmap bm7;
  291. bm7.LoadBitmap(IDB_BITMAP7);
  292. CDC dcMem7;
  293. dcMem7.CreateCompatibleDC(pDC);
  294.     CBitmap*pOldbmp7=dcMem7.SelectObject(&bm7);
  295.     pDC->BitBlt(850,200,950,250,&dcMem7,0,0,SRCCOPY);
  296. dcMem.SelectObject(pOldbmp7);
  297. CBitmap bm8;
  298. bm8.LoadBitmap(IDB_BITMAP8);
  299. CDC dcMem8;
  300. dcMem8.CreateCompatibleDC(pDC);
  301.     CBitmap*pOldbmp8=dcMem8.SelectObject(&bm8);
  302.     pDC->BitBlt(850,480,950,530,&dcMem8,0,0,SRCCOPY);
  303. dcMem.SelectObject(pOldbmp8);
  304.     if(born)
  305. {
  306. if(bornpoint)
  307. {
  308.    PutPicture(3,1,1,1,pDC);
  309.    bornpoint=0;
  310. }
  311. else
  312. {
  313. PutPicture(4,1,1,1,pDC);
  314. bornpoint=1;
  315. }
  316. born--;
  317. }
  318. if(!born&&playertankelive)
  319.     PutPicture(player, countx, county,1,pDC);
  320. if(!playertankelive)
  321. {
  322.     char n[50];
  323. sprintf(n,"%s","出师未捷身先死,可惜、可惜!");
  324. pDC->TextOut(168,182,n);
  325. CBitmap bm4;
  326. bm4.LoadBitmap(IDB_BITMAP4);
  327. CDC dcMem4;
  328. dcMem4.CreateCompatibleDC(pDC);
  329. CBitmap*pOldbmp4=dcMem4.SelectObject(&bm4);
  330. pDC->BitBlt(200,200,328,328,&dcMem4,0,0,SRCCOPY);
  331. dcMem.SelectObject(pOldbmp4);
  332. KillTimer(1);
  333. }
  334. if(cannon||playerbulletrun)
  335. {
  336. if(cannon)
  337. playerbulletdirection=county;
  338. if(1==playerbulletdirection)
  339. {
  340. if(cannon)
  341. {
  342.         playerbulletx=playerx+11;
  343.         playerbullety=playery-5;
  344. cannon=0;
  345. }
  346. if(playerbullety>50)
  347. {
  348. PutBullet(player,1,pDC);
  349. playerbullety-=25;
  350. }
  351. }
  352. else if(2==playerbulletdirection)
  353. {
  354. if(cannon)
  355. {
  356.         playerbulletx=playerx+28;
  357.         playerbullety=playery+11;
  358.     cannon=0;
  359. }
  360. if(playerbulletx<800)
  361. {
  362. PutBullet(player,1,pDC);
  363. playerbulletx+=25;
  364. if(playerbulletx>=778)
  365. {
  366. Putexplosion(player,1,4,pDC);
  367. playerbulletx=0;
  368. }
  369. }
  370. }
  371. else if(3==playerbulletdirection)
  372. {
  373. if(cannon)
  374. {
  375.         playerbulletx=playerx+11;
  376.         playerbullety=playery+28;
  377. cannon=0;
  378. }
  379. if(playerbullety<600)
  380. {
  381. PutBullet(player,1,pDC);
  382. playerbullety+=25;
  383. }
  384. }
  385. else if(4==playerbulletdirection)
  386. {
  387. if(cannon)
  388. {
  389.         playerbulletx=playerx-5;
  390.         playerbullety=playery+11;
  391. cannon=0;
  392. }
  393. if(playerbulletx>120)
  394. {
  395. PutBullet(player,1,pDC);
  396. playerbulletx-=25;
  397. if(playerbulletx<=132)
  398. {
  399. Putexplosion(player,1,4,pDC);
  400. playerbulletx=0;
  401. }
  402. }
  403. }
  404. }
  405. for(int num=0;num<MAXNUM;num++)
  406. {
  407. srand(num*time(0)+1);
  408. emerydirection[num]=rand()%4+1;
  409. if(emerytankelive[num])
  410. {
  411.     PutPicture(emery, countx, emerydirection[num],num,pDC);
  412.     if(emerycannon[num]||emerybulletrun[num])
  413. {
  414.          if(emerycannon[num])
  415.          emerybulletdirection[num]=emerydirection[num];
  416.          if(1==emerybulletdirection[num])
  417. {
  418.          if(emerycannon[num])
  419. {
  420.                 emerybulletx[num]=emeryx[num]+11;
  421.                 emerybullety[num]=emeryy[num]-5;
  422.          emerycannon[num]=0;
  423. }
  424.          if(emerybullety[num]>50)
  425. {
  426.          PutBullet(emery,num,pDC);
  427.          emerybullety[num]-=25;
  428. }
  429. }
  430.          else if(2==emerybulletdirection[num])
  431. {
  432.         if(emerycannon[num])
  433. {
  434.                 emerybulletx[num]=emeryx[num]+28;
  435.                 emerybullety[num]=emeryy[num]+11;
  436.             emerycannon[num]=0;
  437. }
  438.          if(emerybulletx[num]<800)
  439. {
  440.         PutBullet(emery,num,pDC);
  441.          emerybulletx[num]+=25;
  442.          if(emerybulletx[num]>=778)
  443. {
  444.           Putexplosion(3,1,num,pDC);
  445. emerybulletx[num]=0;
  446. }
  447. }
  448. }
  449.          else if(3==emerybulletdirection[num])
  450. {
  451.          if(emerycannon[num])
  452. {
  453.                 emerybulletx[num]=emeryx[num]+11;
  454.                 emerybullety[num]=emeryy[num]+28;
  455.           emerycannon[num]=0;
  456. }
  457.          if(emerybullety[num]<600)
  458. {
  459.          PutBullet(emery,num,pDC);
  460.          emerybullety[num]+=25;
  461. }
  462. }
  463.          else if(4==emerybulletdirection[num])
  464. {
  465.          if(emerycannon[num])
  466. {
  467.                  emerybulletx[num]=emeryx[num]-5;
  468.                  emerybullety[num]=emeryy[num]+11;
  469.              emerycannon[num]=0;
  470. }
  471.          if(emerybulletx[num]>120)
  472. {
  473.          PutBullet(emery,num,pDC);
  474.          emerybulletx[num]-=25;
  475.           if(emerybulletx[num]<=132)
  476. {
  477.              Putexplosion(3,1,num,pDC);
  478. emerybulletx[num]=0;
  479. }
  480. }
  481. }
  482. if((emerybulletx[num]-playerx)>=0&&(emerybulletx[num]-playerx)<=28&&(emerybullety[num]-playery)>=0&&(emerybullety[num]-playery)<=28)
  483. {
  484. Putexplosion(4,emerybulletdirection[num],num,pDC);
  485.         playertankelive--;
  486. emerybulletx[num]=0;
  487. }
  488. }
  489.     if((playerbulletx-emeryx[num])>=0 &&(playerbulletx-emeryx[num])<=28&&(playerbullety-emeryy[num])>=0 && (playerbullety-emeryy[num])<=28)
  490. {
  491.      Putexplosion(2,playerbulletdirection,4,pDC);
  492.      emerytankelive[num]=0;
  493. emerynum--;
  494. playerbulletx=0;
  495. }
  496. if(!emerynum)
  497. {
  498. char n[50];
  499. sprintf(n,"%s","胜利、胜利 ! \(^o^)/ 欧耶,奥耶!");
  500. pDC->TextOut(178,182,n);
  501. CBitmap bm5;
  502. bm5.LoadBitmap(IDB_BITMAP5);
  503. CDC dcMem5;
  504. dcMem5.CreateCompatibleDC(pDC);
  505. CBitmap*pOldbmp5=dcMem5.SelectObject(&bm5);
  506. pDC->BitBlt(200,200,340,340,&dcMem5,0,0,SRCCOPY);
  507. dcMem.SelectObject(pOldbmp5);
  508. KillTimer(1);
  509. }
  510. char n2[30];
  511. sprintf(n2,"%s","敌军坦克剩余数:");
  512. pDC->TextOut(850,300,n2);
  513. char n1[30];
  514. sprintf(n1,"%d",emerynum);
  515. pDC->TextOut(965,300,n1);
  516. char n5[30];
  517. sprintf(n5,"%s","歼灭敌军坦克数:");
  518. pDC->TextOut(850,350,n5);
  519. char n6[30];
  520. sprintf(n6,"%d",MAXNUM-emerynum);
  521. pDC->TextOut(965,350,n6);
  522. pDC->Rectangle(CRect(849,419,962,438));
  523. char n3[30];
  524. sprintf(n3,"%s","我军坦克生命数:");
  525. pDC->TextOut(850,400,n3);
  526. char n4[30];
  527. if(3==playertankelive)
  528. {
  529.     sprintf(n4,"%s","|||||||||||||||||||||||||||");
  530.     pDC->TextOut(850,420,n4);
  531. }
  532. if(2==playertankelive)
  533. {
  534.     sprintf(n4,"%s","||||||||||||||||||");
  535.     pDC->TextOut(850,420,n4);
  536. }
  537. if(1==playertankelive)
  538. {
  539.     sprintf(n4,"%s","|||||||||");
  540.     pDC->TextOut(850,420,n4);
  541. }
  542. }
  543. }
  544. // if(layerbulletx>775 && playerbulletx<145 && playerbullety<75 && playerbullety>575)
  545. // Putexplosion(player,pDC);
  546. }
  547. /////////////////////////////////////////////////////////////////////////////
  548. // CTanke_huangleleView printing
  549. BOOL CTanke_huangleleView::OnPreparePrinting(CPrintInfo* pInfo)
  550. {
  551. // default preparation
  552. return DoPreparePrinting(pInfo);
  553. }
  554. void CTanke_huangleleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  555. {
  556. // TODO: add extra initialization before printing
  557. }
  558. void CTanke_huangleleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  559. {
  560. // TODO: add cleanup after printing
  561. }
  562. /////////////////////////////////////////////////////////////////////////////
  563. // CTanke_huangleleView diagnostics
  564. #ifdef _DEBUG
  565. void CTanke_huangleleView::AssertValid() const
  566. {
  567. CView::AssertValid();
  568. }
  569. void CTanke_huangleleView::Dump(CDumpContext& dc) const
  570. {
  571. CView::Dump(dc);
  572. }
  573. CTanke_huangleleDoc* CTanke_huangleleView::GetDocument() // non-debug version is inline
  574. {
  575. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTanke_huangleleDoc)));
  576. return (CTanke_huangleleDoc*)m_pDocument;
  577. }
  578. #endif //_DEBUG
  579. /////////////////////////////////////////////////////////////////////////////
  580. // CTanke_huangleleView message handlers
  581. void CTanke_huangleleView::OnStart() 
  582. {
  583. // TODO: Add your command handler code here
  584. SetTimer(1,200,NULL);
  585. for(int i=0;i<MAXNUM;i++)
  586. {
  587. emerycannon[i]=1;
  588. }
  589. }
  590. void CTanke_huangleleView::OnStop() 
  591. {
  592. // TODO: Add your command handler code here
  593. KillTimer(1);
  594. }
  595. void CTanke_huangleleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  596. {
  597. // TODO: Add your message handler code here and/or call default
  598. CDC*pDC=GetDC();
  599. if(37==nChar)  //左
  600. {
  601. county=4;
  602.     playerx-=3;
  603. if(playerx<120)
  604. playerx=120;
  605. }
  606.     if(39==nChar)   //右
  607. {
  608. county=2;
  609. playerx+=3;
  610. if(playerx>770)
  611. playerx=770;
  612. }
  613.     if(38==nChar)  //上
  614. {
  615. county=1;
  616. playery-=3;
  617. if(playery>622)
  618. playery=622;
  619. }
  620.     if(40==nChar)   //下
  621. {
  622. county=3;
  623. playery+=3;
  624. if(playery<50)
  625. playery=50;
  626. }
  627. if(32==nChar)
  628. {
  629. cannon=1;
  630. }
  631. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  632. }
  633. void CTanke_huangleleView::OnTimer(UINT nIDEvent) 
  634. {
  635. // TODO: Add your message handler code here and/or call default
  636. InvalidateRect(CRect(120,50,800,600));
  637. InvalidateRect(CRect(955,300,975,320));
  638. InvalidateRect(CRect(955,350,975,370));
  639. InvalidateRect(CRect(849,419,962,438));
  640. // InvalidateRect(CRect(playerx-28,playery-28,playerx+56,playery+56));
  641. play++;
  642. if(play>4||play<1)
  643. play=1;
  644. countx=play;
  645. playerbulletrun=(playerbulletx<800 && playerbulletx>120 && playerbullety>50 && playerbullety<600);
  646. // explosion=(playerbulletrun&&playerbulletx>775 && playerbulletx<145 && playerbullety<75 && playerbullety>575);
  647. for(int i=0;i<MAXNUM;i++)
  648. {
  649. emerybulletrun[i]=(emerybulletx[i]<800 && emerybulletx[i]>120 && emerybullety[i]>50 && emerybullety[i]<600);
  650.         if(!emerybulletrun[i])
  651. emerycannon[i]=1;
  652. }
  653.     
  654. CView::OnTimer(nIDEvent);
  655. }
  656. void CTanke_huangleleView::OnLButtonDown(UINT nFlags, CPoint point) 
  657. {
  658. // TODO: Add your message handler code here and/or call default
  659. if(point.x>850&&point.x<950&&point.y>100&&point.y<150)
  660. {
  661. SetTimer(1,200,NULL);
  662. }
  663. if(point.x>850&&point.x<950&&point.y>200&&point.y<250)
  664. {
  665. KillTimer(1);
  666. }
  667. if(point.x>850&&point.x<950&&point.y>480&&point.y<530)
  668. {
  669. CExplanation d;
  670. d.DoModal();
  671. }
  672. CView::OnLButtonDown(nFlags, point);
  673. }