EnermyPlace.cpp
资源名称:LwGame2.0.rar [点击查看]
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:3k
源码类别:
射击游戏
开发平台:
Visual C++
- /********************************************************************
- * 空运爆发 *
- * Version 2.0 *
- * 本游戏全部代码由: *
- * 冲天实验室 梁锋 编写 *
- * 邮箱:lenwine@126.com *
- * bbs: http://free2.e-168.cn/lenwind (正在开发中...) *
- **********************************************************************/
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- EnermyPlace::EnermyPlace(Manager *mgr)
- {
- mManager=mgr;
- RefreshStress();
- }
- EnermyPlace::~EnermyPlace()
- {
- list<Brock*>::iterator b,bk;;
- b=BrockList.begin();
- bk=BrockList.end();
- while(b!=bk)
- {
- delete *b;
- b++;
- }
- }
- Brock* EnermyPlace::GetOneBrock()
- {
- BrockFind=-1;
- BrockValue=BrockList.size();
- if(BrockValue==0)
- return NULL;
- oNowBrock=BrockList.end();
- return GetTwoBrock();
- }
- Brock* EnermyPlace::GetTwoBrock()
- {
- BrockFind++;
- oNowBrock++;
- while((BrockFind<BrockValue)&&(*oNowBrock)->Work==false)
- {
- delete *oNowBrock;
- BrockValue--;
- oNowBrock=BrockList.erase(oNowBrock);
- }
- if(oNowBrock==BrockList.end())
- return NULL;
- else
- return *oNowBrock;
- }
- //创建新敌机
- void EnermyPlace::NewBrock(int x,int y)
- {
- int i,j;
- Brock::BROCKSTYLE BrockStyle=(Brock::BROCKSTYLE)(rand() % Brock::BROCKVALUE);
- Brock *bBrock;
- switch(BrockStyle)
- {
- case Brock::BROCKA:
- bBrock=new BrockA(mManager,x+80,y-80);
- BrockList.push_back(bBrock);
- break;
- case Brock::BROCKB:
- bBrock=new BrockB(mManager,x+80,y-80);
- BrockList.push_back(bBrock);
- break;
- case Brock::BROCKC:
- if(rand()%3>0)break;
- j=rand()%4+1;
- switch(rand()%4)
- {
- case 0:
- if(x+j*50>Manager::Imglong)
- x=Manager::Imglong-j*50;
- for(i=0;i<j;i++)
- {
- bBrock=new BrockC(mManager,x+i*50,y-i*50);
- BrockList.push_back(bBrock);
- }
- break;
- case 1:
- if(x<j*50)
- x=j*50;
- for(i=0;i<j;i++)
- {
- bBrock=new BrockC(mManager,x-i*50,y-i*50);
- BrockList.push_back(bBrock);
- }
- break;
- case 2:
- for(i=0;i<j;i++)
- {
- bBrock=new BrockC(mManager,x,y-i*70);
- BrockList.push_back(bBrock);
- }
- break;
- case 3:
- if(x+j*50>Manager::Imglong)
- x=Manager::Imglong-j*50;
- for(i=0;i<j;i++)
- {
- bBrock=new BrockC(mManager,x+i*70,y);
- BrockList.push_back(bBrock);
- }
- }
- case Brock::BROCKD:
- bBrock=new BrockD(mManager,x+80,y-80);
- BrockList.push_back(bBrock);
- break;
- case Brock::BROCKE:
- bBrock=new BrockE(mManager,x+100,y-100);
- BrockList.push_back(bBrock);
- break;
- case Brock::BROCKF:
- bBrock=new BrockF(mManager,x+120,y-120);
- BrockList.push_back(bBrock);
- break;
- }
- }
- void EnermyPlace::Update()
- {
- if(rand()<stress)
- NewBrock(rand()%mManager->Imglong,-1);
- //刷新敌机
- Brock *bBrock=GetOneBrock();
- while(bBrock)
- {
- bBrock->Update();
- bBrock=GetTwoBrock();
- }
- }
- void EnermyPlace::AddStress()
- {
- stress=(int)(stress*1.6);
- }
- void EnermyPlace::RefreshStress()
- {
- stress=500;
- }