tanke_huangleleView.cpp
资源名称:TankWar.rar [点击查看]
上传用户:jindun001
上传日期:2021-02-02
资源大小:13780k
文件大小:18k
源码类别:
射击游戏
开发平台:
Visual C++
- // tanke_huangleleView.cpp : implementation of the CTanke_huangleleView class
- //
- #include "stdafx.h"
- #include "tanke_huanglele.h"
- #include "tanke_huangleleDoc.h"
- #include "tanke_huangleleView.h"
- #include "Explanation.h"
- #pragma comment(lib,"ReadPicture_dll.lib")
- extern "C" _declspec(dllexport)void ReadFilePicture(int *arr ,int point ,int Wide,int High);
- #pragma comment(lib,"PutBullet.lib")
- extern "C" _declspec(dllexport)void PutFileBullet(int *arr ,int point );
- #pragma comment(lib,"Putexplosion_dll.lib")
- extern "C" _declspec(dllexport)void PutFileexplosion(int *arr ,int point );
- #pragma comment(lib,"Putfileborn_dll.lib")
- extern "C" _declspec(dllexport)void PutFileborn(int *arr ,int point );
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- int a[300][300];
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView
- IMPLEMENT_DYNCREATE(CTanke_huangleleView, CView)
- BEGIN_MESSAGE_MAP(CTanke_huangleleView, CView)
- //{{AFX_MSG_MAP(CTanke_huangleleView)
- ON_COMMAND(IDC_START, OnStart)
- ON_COMMAND(IDC_STOP, OnStop)
- ON_WM_KEYDOWN()
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView construction/destruction
- void PutPicture(int flag,int countx,int county,int num,CDC* pDC)
- {
- int kx1=sizetangke*(countx-1);
- int kx2=sizetangke*countx;
- int ky1=sizetangke*(county-1);
- int ky2=sizetangke*county;
- if(1==flag)
- {
- for(int i=kx1;i<kx2;i++)
- for(int j=ky1;j<ky2;j++)
- {
- if(playerfile[i][j]!=RGB(0,0,0))
- pDC->SetPixel(playerx+(i-kx1),playery+(j-ky1),playerfile[i][j]);
- }
- }
- if(2==flag)
- {
- if(1==county)
- emeryy[num]-=17;
- else if(2==county)
- emeryx[num]+=17;
- else if(3==county)
- emeryy[num]+=17;
- else if(4==county)
- emeryx[num]-=17;
- if(emeryy[num]>630)
- emeryy[num]=630;
- if(emeryy[num]<20)
- emeryy[num]=20;
- if(emeryx[num]>770)
- emeryx[num]=770;
- if(emeryx[num]<120)
- emeryx[num]=120;
- for(int i=kx1;i<kx2;i++)
- for(int j=ky1;j<ky2;j++)
- {
- if(emeryfile[i][j]!=RGB(0,0,0))
- pDC->SetPixel(emeryx[num]+(i-kx1),emeryy[num]+(j-ky1),emeryfile[i][j]);
- }
- }
- if(3==flag)
- {
- for(int i=0;i<32;i++)
- for(int j=0;j<32;j++)
- {
- if(bornarr1[i][j]!=RGB(255,255,255))
- pDC->SetPixel(playerx+i,playery+i,bornarr1[i][j]);
- }
- }
- if(4==flag)
- {
- for(int i=0;i<32;i++)
- for(int j=0;j<32;j++)
- {
- if(bornarr2[i][j]!=RGB(255,255,255))
- pDC->SetPixel(playerx+i,playery+j,bornarr2[i][j]);
- }
- }
- }
- void PutBullet(int mark,int num,CDC* pDC)
- {
- if(1==mark)
- {
- if(playerbulletx<775 && playerbulletx>145 && playerbullety>75 && playerbullety<575)
- {
- for(int i=0;i<7;i++)
- for(int j=0;j<7;j++)
- {
- if(playerbulletfile[i][j]!=RGB(255,255,255))
- pDC->SetPixel(playerbulletx+i,playerbullety+j,playerbulletfile[i][j]);
- }
- }
- }
- if(2==mark)
- {
- if(emerybulletx[num]<775 && emerybulletx[num]>145 && emerybullety[num]>75 && emerybullety[num]<575)
- {
- for(int i=0;i<7;i++)
- for(int j=0;j<7;j++)
- {
- if(emerybulletfile[i][j]!=RGB(255,255,255))
- pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]+j,emerybulletfile[i][j]);
- }
- }
- }
- }
- void Putexplosion(int mark,int point,int num,CDC*pDC)
- {
- if(1==mark)
- {
- for(int i=0;i<28;i++)
- for(int j=0;j<28;j++)
- {
- //if(playerbulletfile[i][j]!=RGB(4,4,4))
- pDC->SetPixel(playerbulletx+i,playerbullety-13+j,explosionarr1[i][j]);
- }
- }
- if(3==mark)
- {
- for(int i=0;i<28;i++)
- for(int j=0;j<28;j++)
- {
- //if(explosionarr1[i][j]!=RGB(4,4,4))
- pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-13+j,explosionarr1[i][j]);
- }
- }
- if(2==mark)
- {
- for(int i=0;i<64;i++)
- for(int j=0;j<64;j++)
- {
- //if(explosionarr2[i][j]!=RGB(4,4,4))
- if(1==point)
- {
- pDC->SetPixel(playerbulletx-32+i,playerbullety+j,explosionarr2[i][j]);
- }
- if(2==point)
- {
- pDC->SetPixel(playerbulletx+i,playerbullety-32+j,explosionarr2[i][j]);
- }
- if(3==point)
- {
- pDC->SetPixel(playerbulletx-32+i,playerbullety-14+j,explosionarr2[i][j]);
- }
- if(4==point)
- {
- pDC->SetPixel(playerbulletx+i,playerbullety-32+j,explosionarr2[i][j]);
- }
- }
- }
- if(4==mark)
- {
- for(int i=0;i<64;i++)
- for(int j=0;j<64;j++)
- {
- //if(playerbulletfile[i][j]!=RGB(4,4,4))
- if(1==point)
- {
- pDC->SetPixel(emerybulletx[num]-32+i,emerybullety[num]+j,explosionarr2[i][j]);
- }
- if(2==point)
- {
- pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-32+j,explosionarr2[i][j]);
- }
- if(3==point)
- {
- pDC->SetPixel(emerybulletx[num]-32+i,emerybullety[num]-14+j,explosionarr2[i][j]);
- }
- if(4==point)
- {
- pDC->SetPixel(emerybulletx[num]+i,emerybullety[num]-32+j,explosionarr2[i][j]);
- }
- born=6;
- }
- }
- }
- CTanke_huangleleView::CTanke_huangleleView()
- {
- // TODO: add construction code here
- ReadFilePicture(playerfile[0],player,112,112);
- ReadFilePicture(emeryfile[0],emery,112,112);
- PutFileBullet(playerbulletfile[0] ,player );
- PutFileBullet(emerybulletfile[0] ,emery );
- PutFileexplosion(explosionarr1[0] ,player);
- PutFileexplosion(explosionarr2[0] ,emery);
- PutFileborn(bornarr1[0] , player);
- PutFileborn(bornarr2[0] ,emery);
- emerynum=MAXNUM;
- playerx=506;
- playery=336;
- playertankelive=3;
- born=0;
- countx=2;
- county=1;
- play=2;
- playerbulletx=0;
- playerbullety=0;
- cannon=0;
- playerbulletrun=0;
- playerbulletdirection=0;
- //CRect rc(playerx-28,playery-28,playerx+28,playery+28);
- CRect rc(playerx,playery,playerx+28,playery+28);
- for(int i=0;i<MAXNUM;i++)
- {
- srand(i*time(0)+3);
- emeryx[i]=rand()%800;
- emeryy[i]=rand()%600;
- if(emeryy[i]>500)
- emeryy[i]=500;
- if(emeryy[i]<120)
- emeryy[i]=120;
- emerydirection[i]=rand()%4+1;
- emerytankelive[i]=1;
- // CRect remery[i](emeryx[i],emeryy[i],emeryx[i]+28,emeryy[i]+28);
- }
- }
- CTanke_huangleleView::~CTanke_huangleleView()
- {
- }
- BOOL CTanke_huangleleView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView drawing
- void CTanke_huangleleView::OnDraw(CDC* pDC)
- {
- CTanke_huangleleDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- pDC->Rectangle(CRect(120,50,800,600));
- CBitmap bm3;
- bm3.LoadBitmap(IDB_BITMAP3);
- CDC dcMem3;
- dcMem3.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp3=dcMem3.SelectObject(&bm3);
- pDC->BitBlt(0,0,640,40,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(640,0,800,40,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(0,600,640,1080,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(640,600,800,1080,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(0,0,120,480,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(0,480,120,960,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(800,0,1280,480,&dcMem3,0,0,SRCCOPY);
- pDC->BitBlt(800,480,1280,960,&dcMem3,0,0,SRCCOPY);
- dcMem3.SelectObject(pOldbmp3);
- CBitmap bm;
- bm.LoadBitmap(IDB_BITMAP1);
- CDC dcMem;
- dcMem.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp=dcMem.SelectObject(&bm);
- pDC->BitBlt(88,18,120,592,&dcMem,0,0,SRCCOPY);
- pDC->BitBlt(800,18,832,592,&dcMem,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp);
- CBitmap bm1;
- bm1.LoadBitmap(IDB_BITMAP2);
- CDC dcMem1;
- dcMem1.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp1=dcMem1.SelectObject(&bm1);
- pDC->BitBlt(120,18,680,50,&dcMem1,0,0,SRCCOPY);
- pDC->BitBlt(120,600,680,632,&dcMem1,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp1);
- CBitmap bm6;
- bm6.LoadBitmap(IDB_BITMAP6);
- CDC dcMem6;
- dcMem6.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp6=dcMem6.SelectObject(&bm6);
- pDC->BitBlt(850,100,950,150,&dcMem6,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp6);
- CBitmap bm7;
- bm7.LoadBitmap(IDB_BITMAP7);
- CDC dcMem7;
- dcMem7.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp7=dcMem7.SelectObject(&bm7);
- pDC->BitBlt(850,200,950,250,&dcMem7,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp7);
- CBitmap bm8;
- bm8.LoadBitmap(IDB_BITMAP8);
- CDC dcMem8;
- dcMem8.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp8=dcMem8.SelectObject(&bm8);
- pDC->BitBlt(850,480,950,530,&dcMem8,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp8);
- if(born)
- {
- if(bornpoint)
- {
- PutPicture(3,1,1,1,pDC);
- bornpoint=0;
- }
- else
- {
- PutPicture(4,1,1,1,pDC);
- bornpoint=1;
- }
- born--;
- }
- if(!born&&playertankelive)
- PutPicture(player, countx, county,1,pDC);
- if(!playertankelive)
- {
- char n[50];
- sprintf(n,"%s","出师未捷身先死,可惜、可惜!");
- pDC->TextOut(168,182,n);
- CBitmap bm4;
- bm4.LoadBitmap(IDB_BITMAP4);
- CDC dcMem4;
- dcMem4.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp4=dcMem4.SelectObject(&bm4);
- pDC->BitBlt(200,200,328,328,&dcMem4,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp4);
- KillTimer(1);
- }
- if(cannon||playerbulletrun)
- {
- if(cannon)
- playerbulletdirection=county;
- if(1==playerbulletdirection)
- {
- if(cannon)
- {
- playerbulletx=playerx+11;
- playerbullety=playery-5;
- cannon=0;
- }
- if(playerbullety>50)
- {
- PutBullet(player,1,pDC);
- playerbullety-=25;
- }
- }
- else if(2==playerbulletdirection)
- {
- if(cannon)
- {
- playerbulletx=playerx+28;
- playerbullety=playery+11;
- cannon=0;
- }
- if(playerbulletx<800)
- {
- PutBullet(player,1,pDC);
- playerbulletx+=25;
- if(playerbulletx>=778)
- {
- Putexplosion(player,1,4,pDC);
- playerbulletx=0;
- }
- }
- }
- else if(3==playerbulletdirection)
- {
- if(cannon)
- {
- playerbulletx=playerx+11;
- playerbullety=playery+28;
- cannon=0;
- }
- if(playerbullety<600)
- {
- PutBullet(player,1,pDC);
- playerbullety+=25;
- }
- }
- else if(4==playerbulletdirection)
- {
- if(cannon)
- {
- playerbulletx=playerx-5;
- playerbullety=playery+11;
- cannon=0;
- }
- if(playerbulletx>120)
- {
- PutBullet(player,1,pDC);
- playerbulletx-=25;
- if(playerbulletx<=132)
- {
- Putexplosion(player,1,4,pDC);
- playerbulletx=0;
- }
- }
- }
- }
- for(int num=0;num<MAXNUM;num++)
- {
- srand(num*time(0)+1);
- emerydirection[num]=rand()%4+1;
- if(emerytankelive[num])
- {
- PutPicture(emery, countx, emerydirection[num],num,pDC);
- if(emerycannon[num]||emerybulletrun[num])
- {
- if(emerycannon[num])
- emerybulletdirection[num]=emerydirection[num];
- if(1==emerybulletdirection[num])
- {
- if(emerycannon[num])
- {
- emerybulletx[num]=emeryx[num]+11;
- emerybullety[num]=emeryy[num]-5;
- emerycannon[num]=0;
- }
- if(emerybullety[num]>50)
- {
- PutBullet(emery,num,pDC);
- emerybullety[num]-=25;
- }
- }
- else if(2==emerybulletdirection[num])
- {
- if(emerycannon[num])
- {
- emerybulletx[num]=emeryx[num]+28;
- emerybullety[num]=emeryy[num]+11;
- emerycannon[num]=0;
- }
- if(emerybulletx[num]<800)
- {
- PutBullet(emery,num,pDC);
- emerybulletx[num]+=25;
- if(emerybulletx[num]>=778)
- {
- Putexplosion(3,1,num,pDC);
- emerybulletx[num]=0;
- }
- }
- }
- else if(3==emerybulletdirection[num])
- {
- if(emerycannon[num])
- {
- emerybulletx[num]=emeryx[num]+11;
- emerybullety[num]=emeryy[num]+28;
- emerycannon[num]=0;
- }
- if(emerybullety[num]<600)
- {
- PutBullet(emery,num,pDC);
- emerybullety[num]+=25;
- }
- }
- else if(4==emerybulletdirection[num])
- {
- if(emerycannon[num])
- {
- emerybulletx[num]=emeryx[num]-5;
- emerybullety[num]=emeryy[num]+11;
- emerycannon[num]=0;
- }
- if(emerybulletx[num]>120)
- {
- PutBullet(emery,num,pDC);
- emerybulletx[num]-=25;
- if(emerybulletx[num]<=132)
- {
- Putexplosion(3,1,num,pDC);
- emerybulletx[num]=0;
- }
- }
- }
- if((emerybulletx[num]-playerx)>=0&&(emerybulletx[num]-playerx)<=28&&(emerybullety[num]-playery)>=0&&(emerybullety[num]-playery)<=28)
- {
- Putexplosion(4,emerybulletdirection[num],num,pDC);
- playertankelive--;
- emerybulletx[num]=0;
- }
- }
- if((playerbulletx-emeryx[num])>=0 &&(playerbulletx-emeryx[num])<=28&&(playerbullety-emeryy[num])>=0 && (playerbullety-emeryy[num])<=28)
- {
- Putexplosion(2,playerbulletdirection,4,pDC);
- emerytankelive[num]=0;
- emerynum--;
- playerbulletx=0;
- }
- if(!emerynum)
- {
- char n[50];
- sprintf(n,"%s","胜利、胜利 ! \(^o^)/ 欧耶,奥耶!");
- pDC->TextOut(178,182,n);
- CBitmap bm5;
- bm5.LoadBitmap(IDB_BITMAP5);
- CDC dcMem5;
- dcMem5.CreateCompatibleDC(pDC);
- CBitmap*pOldbmp5=dcMem5.SelectObject(&bm5);
- pDC->BitBlt(200,200,340,340,&dcMem5,0,0,SRCCOPY);
- dcMem.SelectObject(pOldbmp5);
- KillTimer(1);
- }
- char n2[30];
- sprintf(n2,"%s","敌军坦克剩余数:");
- pDC->TextOut(850,300,n2);
- char n1[30];
- sprintf(n1,"%d",emerynum);
- pDC->TextOut(965,300,n1);
- char n5[30];
- sprintf(n5,"%s","歼灭敌军坦克数:");
- pDC->TextOut(850,350,n5);
- char n6[30];
- sprintf(n6,"%d",MAXNUM-emerynum);
- pDC->TextOut(965,350,n6);
- pDC->Rectangle(CRect(849,419,962,438));
- char n3[30];
- sprintf(n3,"%s","我军坦克生命数:");
- pDC->TextOut(850,400,n3);
- char n4[30];
- if(3==playertankelive)
- {
- sprintf(n4,"%s","|||||||||||||||||||||||||||");
- pDC->TextOut(850,420,n4);
- }
- if(2==playertankelive)
- {
- sprintf(n4,"%s","||||||||||||||||||");
- pDC->TextOut(850,420,n4);
- }
- if(1==playertankelive)
- {
- sprintf(n4,"%s","|||||||||");
- pDC->TextOut(850,420,n4);
- }
- }
- }
- // if(layerbulletx>775 && playerbulletx<145 && playerbullety<75 && playerbullety>575)
- // Putexplosion(player,pDC);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView printing
- BOOL CTanke_huangleleView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CTanke_huangleleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CTanke_huangleleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView diagnostics
- #ifdef _DEBUG
- void CTanke_huangleleView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CTanke_huangleleView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CTanke_huangleleDoc* CTanke_huangleleView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTanke_huangleleDoc)));
- return (CTanke_huangleleDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTanke_huangleleView message handlers
- void CTanke_huangleleView::OnStart()
- {
- // TODO: Add your command handler code here
- SetTimer(1,200,NULL);
- for(int i=0;i<MAXNUM;i++)
- {
- emerycannon[i]=1;
- }
- }
- void CTanke_huangleleView::OnStop()
- {
- // TODO: Add your command handler code here
- KillTimer(1);
- }
- void CTanke_huangleleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- CDC*pDC=GetDC();
- if(37==nChar) //左
- {
- county=4;
- playerx-=3;
- if(playerx<120)
- playerx=120;
- }
- if(39==nChar) //右
- {
- county=2;
- playerx+=3;
- if(playerx>770)
- playerx=770;
- }
- if(38==nChar) //上
- {
- county=1;
- playery-=3;
- if(playery>622)
- playery=622;
- }
- if(40==nChar) //下
- {
- county=3;
- playery+=3;
- if(playery<50)
- playery=50;
- }
- if(32==nChar)
- {
- cannon=1;
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CTanke_huangleleView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- InvalidateRect(CRect(120,50,800,600));
- InvalidateRect(CRect(955,300,975,320));
- InvalidateRect(CRect(955,350,975,370));
- InvalidateRect(CRect(849,419,962,438));
- // InvalidateRect(CRect(playerx-28,playery-28,playerx+56,playery+56));
- play++;
- if(play>4||play<1)
- play=1;
- countx=play;
- playerbulletrun=(playerbulletx<800 && playerbulletx>120 && playerbullety>50 && playerbullety<600);
- // explosion=(playerbulletrun&&playerbulletx>775 && playerbulletx<145 && playerbullety<75 && playerbullety>575);
- for(int i=0;i<MAXNUM;i++)
- {
- emerybulletrun[i]=(emerybulletx[i]<800 && emerybulletx[i]>120 && emerybullety[i]>50 && emerybullety[i]<600);
- if(!emerybulletrun[i])
- emerycannon[i]=1;
- }
- CView::OnTimer(nIDEvent);
- }
- void CTanke_huangleleView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(point.x>850&&point.x<950&&point.y>100&&point.y<150)
- {
- SetTimer(1,200,NULL);
- }
- if(point.x>850&&point.x<950&&point.y>200&&point.y<250)
- {
- KillTimer(1);
- }
- if(point.x>850&&point.x<950&&point.y>480&&point.y<530)
- {
- CExplanation d;
- d.DoModal();
- }
- CView::OnLButtonDown(nFlags, point);
- }