Commit b33e06da authored by CjhGm's avatar CjhGm
Browse files

reconstruct code

parent 222634b6
// PlaneWar.cpp : 定义应用程序的类行为。
// AircraftBattle.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "afxwinappex.h"
#include "afxdialogex.h"
#include "PlaneWar.h"
#include "AircraftBattle.h"
#include "MainFrm.h"
#include "PlaneWarDoc.h"
#include "PlaneWarView.h"
#include "AircraftBattleDoc.h"
#include "AircraftBattleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPlaneWarApp
// CAircraftBattleApp
BEGIN_MESSAGE_MAP(CPlaneWarApp, CWinAppEx)
ON_COMMAND(ID_APP_ABOUT, &CPlaneWarApp::OnAppAbout)
BEGIN_MESSAGE_MAP(CAircraftBattleApp, CWinAppEx)
ON_COMMAND(ID_APP_ABOUT, &CAircraftBattleApp::OnAppAbout)
// 基于文件的标准文档命令
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
......@@ -28,9 +28,9 @@ BEGIN_MESSAGE_MAP(CPlaneWarApp, CWinAppEx)
END_MESSAGE_MAP()
// CPlaneWarApp 构造
// CAircraftBattleApp 构造
CPlaneWarApp::CPlaneWarApp()
CAircraftBattleApp::CAircraftBattleApp()
{
m_bHiColorIcons = TRUE;
......@@ -45,20 +45,20 @@ CPlaneWarApp::CPlaneWarApp()
// TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
//为 CompanyName.ProductName.SubProduct.VersionInformation
SetAppID(_T("PlaneWar.AppID.NoVersion"));
SetAppID(_T("AircraftBattle.AppID.NoVersion"));
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CPlaneWarApp 对象
// 唯一的一个 CAircraftBattleApp 对象
CPlaneWarApp theApp;
CAircraftBattleApp theApp;
// CPlaneWarApp 初始化
// CAircraftBattleApp 初始化
BOOL CPlaneWarApp::InitInstance()
BOOL CAircraftBattleApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
......@@ -113,9 +113,9 @@ BOOL CPlaneWarApp::InitInstance()
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CPlaneWarDoc),
RUNTIME_CLASS(CAircraftBattleDoc),
RUNTIME_CLASS(CMainFrame), // 主 SDI 框架窗口
RUNTIME_CLASS(CPlaneWarView));
RUNTIME_CLASS(CAircraftBattleView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
......@@ -141,7 +141,7 @@ BOOL CPlaneWarApp::InitInstance()
return TRUE;
}
int CPlaneWarApp::ExitInstance()
int CAircraftBattleApp::ExitInstance()
{
//TODO: 处理可能已添加的附加资源
AfxOleTerm(FALSE);
......@@ -149,7 +149,7 @@ int CPlaneWarApp::ExitInstance()
return CWinAppEx::ExitInstance();
}
// CPlaneWarApp 消息处理程序
// CAircraftBattleApp 消息处理程序
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
......@@ -188,15 +188,15 @@ BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// 用于运行对话框的应用程序命令
void CPlaneWarApp::OnAppAbout()
void CAircraftBattleApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
// CPlaneWarApp 自定义加载/保存方法
// CAircraftBattleApp 自定义加载/保存方法
void CPlaneWarApp::PreLoadState()
void CAircraftBattleApp::PreLoadState()
{
BOOL bNameValid;
CString strName;
......@@ -208,12 +208,12 @@ void CPlaneWarApp::PreLoadState()
GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
}
void CPlaneWarApp::LoadCustomState()
void CAircraftBattleApp::LoadCustomState()
{
}
void CPlaneWarApp::SaveCustomState()
void CAircraftBattleApp::SaveCustomState()
{
}
// CPlaneWarApp 消息处理程序
\ No newline at end of file
// CAircraftBattleApp 消息处理程序
\ No newline at end of file
// PlaneWar.h : PlaneWar 应用程序的主头文件
// AircraftBattle.h : AircraftBattle 应用程序的主头文件
//
#pragma once
......@@ -10,14 +10,14 @@
#include "resource.h" // 主符号
// CPlaneWarApp:
// 有关此类的实现,请参阅 PlaneWar.cpp
// CAircraftBattleApp:
// 有关此类的实现,请参阅 AircraftBattle.cpp
//
class CPlaneWarApp : public CWinAppEx
class CAircraftBattleApp : public CWinAppEx
{
public:
CPlaneWarApp();
CAircraftBattleApp();
// 重写
......@@ -37,4 +37,4 @@ public:
DECLARE_MESSAGE_MAP()
};
extern CPlaneWarApp theApp;
extern CAircraftBattleApp theApp;
// PlaneWarDoc.cpp : CPlaneWarDoc 类的实现
// AircraftBattleDoc.cpp : CAircraftBattleDoc 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "PlaneWar.h"
#include "AircraftBattle.h"
#endif
#include "PlaneWarDoc.h"
#include "AircraftBattleDoc.h"
#include <propkey.h>
......@@ -17,27 +17,27 @@
#define new DEBUG_NEW
#endif
// CPlaneWarDoc
// CAircraftBattleDoc
IMPLEMENT_DYNCREATE(CPlaneWarDoc, CDocument)
IMPLEMENT_DYNCREATE(CAircraftBattleDoc, CDocument)
BEGIN_MESSAGE_MAP(CPlaneWarDoc, CDocument)
BEGIN_MESSAGE_MAP(CAircraftBattleDoc, CDocument)
END_MESSAGE_MAP()
// CPlaneWarDoc 构造/析构
// CAircraftBattleDoc 构造/析构
CPlaneWarDoc::CPlaneWarDoc()
CAircraftBattleDoc::CAircraftBattleDoc()
{
// TODO: 在此添加一次性构造代码
}
CPlaneWarDoc::~CPlaneWarDoc()
CAircraftBattleDoc::~CAircraftBattleDoc()
{
}
BOOL CPlaneWarDoc::OnNewDocument()
BOOL CAircraftBattleDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
......@@ -51,9 +51,9 @@ BOOL CPlaneWarDoc::OnNewDocument()
// CPlaneWarDoc 序列化
// CAircraftBattleDoc 序列化
void CPlaneWarDoc::Serialize(CArchive& ar)
void CAircraftBattleDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
......@@ -68,7 +68,7 @@ void CPlaneWarDoc::Serialize(CArchive& ar)
#ifdef SHARED_HANDLERS
// 缩略图的支持
void CPlaneWarDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
void CAircraftBattleDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
// 修改此代码以绘制文档数据
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
......@@ -89,7 +89,7 @@ void CPlaneWarDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
}
// 搜索处理程序的支持
void CPlaneWarDoc::InitializeSearchContent()
void CAircraftBattleDoc::InitializeSearchContent()
{
CString strSearchContent;
// 从文档数据设置搜索内容。
......@@ -99,7 +99,7 @@ void CPlaneWarDoc::InitializeSearchContent()
SetSearchContent(strSearchContent);
}
void CPlaneWarDoc::SetSearchContent(const CString& value)
void CAircraftBattleDoc::SetSearchContent(const CString& value)
{
if (value.IsEmpty())
{
......@@ -119,19 +119,19 @@ void CPlaneWarDoc::SetSearchContent(const CString& value)
#endif // SHARED_HANDLERS
// CPlaneWarDoc 诊断
// CAircraftBattleDoc 诊断
#ifdef _DEBUG
void CPlaneWarDoc::AssertValid() const
void CAircraftBattleDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CPlaneWarDoc::Dump(CDumpContext& dc) const
void CAircraftBattleDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CPlaneWarDoc 命令
// CAircraftBattleDoc 命令
// PlaneWarDoc.h : CPlaneWarDoc 类的接口
// AircraftBattleDoc.h : CAircraftBattleDoc 类的接口
//
#pragma once
class CPlaneWarDoc : public CDocument
class CAircraftBattleDoc : public CDocument
{
protected: // 仅从序列化创建
CPlaneWarDoc();
DECLARE_DYNCREATE(CPlaneWarDoc)
CAircraftBattleDoc();
DECLARE_DYNCREATE(CAircraftBattleDoc)
// 特性
public:
......@@ -29,7 +29,7 @@ public:
// 实现
public:
virtual ~CPlaneWarDoc();
virtual ~CAircraftBattleDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
......
// PlaneWarView.cpp : CPlaneWarView 类的实现
// AircraftBattleView.cpp : CAircraftBattleView 类的实现
//
#include "stdafx.h"
......@@ -10,11 +10,11 @@
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "PlaneWar.h"
#include "AircraftBattle.h"
#endif
#include "PlaneWarDoc.h"
#include "PlaneWarView.h"
#include "AircraftBattleDoc.h"
#include "AircraftBattleView.h"
#include "CEnemy.h"
#include "MyPlane.h"
#include "CBullet.h"
......@@ -24,15 +24,15 @@
#endif
// CPlaneWarView
// CAircraftBattleView
IMPLEMENT_DYNCREATE(CPlaneWarView, CView)
IMPLEMENT_DYNCREATE(CAircraftBattleView, CView)
BEGIN_MESSAGE_MAP(CPlaneWarView, CView)
BEGIN_MESSAGE_MAP(CAircraftBattleView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CPlaneWarView::OnFilePrintPreview)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CAircraftBattleView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_CREATE()
......@@ -44,20 +44,20 @@ BEGIN_MESSAGE_MAP(CPlaneWarView, CView)
ON_WM_CLOSE()
END_MESSAGE_MAP()
// CPlaneWarView 构造/析构
// CAircraftBattleView 构造/析构
CPlaneWarView::CPlaneWarView()
CAircraftBattleView::CAircraftBattleView()
{
//默认战机飞行速度、战机生命值、战机得分、关卡、是否过关、是否暂停
// TODO: 在此处添加构造代码
}
CPlaneWarView::~CPlaneWarView()
CAircraftBattleView::~CAircraftBattleView()
{
}
BOOL CPlaneWarView::PreCreateWindow(CREATESTRUCT& cs)
BOOL CAircraftBattleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
......@@ -65,10 +65,10 @@ BOOL CPlaneWarView::PreCreateWindow(CREATESTRUCT& cs)
return CView::PreCreateWindow(cs);
}
// CPlaneWarView 绘制
void CPlaneWarView::OnDraw(CDC* pDC)
// CAircraftBattleView 绘制
void CAircraftBattleView::OnDraw(CDC* pDC)
{
CPlaneWarDoc* pDoc = GetDocument();
CAircraftBattleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
......@@ -76,73 +76,63 @@ void CPlaneWarView::OnDraw(CDC* pDC)
// TODO: 在此处为本机数据添加绘制代码
}
// CPlaneWarView 打印
// CAircraftBattleView 打印
void CPlaneWarView::OnFilePrintPreview()
void CAircraftBattleView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CPlaneWarView::OnPreparePrinting(CPrintInfo* pInfo)
BOOL CAircraftBattleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CPlaneWarView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
void CAircraftBattleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CPlaneWarView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
void CAircraftBattleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CPlaneWarView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
void CAircraftBattleView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CPlaneWarView 诊断
// CAircraftBattleView 诊断
#ifdef _DEBUG
void CPlaneWarView::AssertValid() const
void CAircraftBattleView::AssertValid() const
{
CView::AssertValid();
}
void CPlaneWarView::Dump(CDumpContext& dc) const
void CAircraftBattleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CPlaneWarDoc* CPlaneWarView::GetDocument() const // 非调试版本是内联的
CAircraftBattleDoc* CAircraftBattleView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPlaneWarDoc)));
return (CPlaneWarDoc*)m_pDocument;
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAircraftBattleDoc)));
return (CAircraftBattleDoc*)m_pDocument;
}
#endif //_DEBUG
//重写实现
//获得速度
int CPlaneWarView::GetSpeed()
{
return this->speed;
}
//设置速度
void CPlaneWarView::SetSpeed(int speed)
{
this->speed = speed;
}
// CPlaneWarView 消息处理程序
// CAircraftBattleView 消息处理程序
//视图创建监听
int CPlaneWarView::OnCreate(LPCREATESTRUCT lpCreateStruct)
int CAircraftBattleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
......@@ -170,24 +160,8 @@ int CPlaneWarView::OnCreate(LPCREATESTRUCT lpCreateStruct)
//参数初始化
myplane = new CMyPlane(FALSE);
isBoss = FALSE;
speed = DEFAULT_SPEED;
myLife = DEFAULT_LIFE;
lifeNum = DEFAULT_LIFE_COUNT;
lifeCount = 1;
passScore = 0;
myScore = 0;
bossLoaded = TRUE;
passNum = DEFAULT_PASS;
isPass = 0;
isPause = FALSE;
magicCount = 0;
bloodExist = FALSE;
isProtect = FALSE;
isUpdate = FALSE;
test = FALSE;
isStop = FALSE;
isStarted = FALSE;
isStarted = false;
isPause = false;
SetTimer(4, 40, NULL);//背景滚动定时器
SetMyTimer();
......@@ -195,7 +169,7 @@ int CPlaneWarView::OnCreate(LPCREATESTRUCT lpCreateStruct)
}
//计时器监听
void CPlaneWarView::OnTimer(UINT_PTR nIDEvent)
void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
......@@ -262,30 +236,30 @@ void CPlaneWarView::OnTimer(UINT_PTR nIDEvent)
}
else {
// 游戏界面
scene.StickScene(&cdc, passNum, rect);
scene.StickScene(&cdc, 1, rect);
if (nIDEvent == 4) {
//滚动背景
scene.MoveBg();
}
//刷新显示战机
// 刷新显示战机
if (myplane != NULL) {
myplane->Draw(&cdc, FALSE, isProtect);
myplane->Draw(&cdc, FALSE, FALSE);
}
//随机添加敌机,敌机随机发射炸弹,此时敌机速度与数量和关卡有关
if (myplane != NULL && isPause == 0 && isBoss == FALSE) {
//敌机产生定时器触发
// 随机添加敌机,敌机随机发射炸弹,此时敌机速度与数量和关卡有关
if (myplane != NULL && !isPause) {
// 敌机产生定时器触发
if (nIDEvent == 2) {
CEnemy* enemy = new CEnemy(rect.right, rect.bottom);
enemyList.AddTail(enemy);//随机产生敌机
enemyList.AddTail(enemy); //随机产生敌机
}
}
//超出边界的敌机进行销毁
// 超出边界的敌机进行销毁
POSITION stPos = NULL, tPos = NULL;
stPos = enemyList.GetHeadPosition();
while (stPos != NULL) {
tPos = stPos;
CEnemy* enemy = (CEnemy*)enemyList.GetNext(stPos);
//判断敌机是否出界
// 判断敌机是否出界
if (enemy->GetPoint().x<rect.left || enemy->GetPoint().x>rect.right
|| enemy->GetPoint().y<rect.top || enemy->GetPoint().y>rect.bottom) {
enemyList.RemoveAt(tPos);
......@@ -293,7 +267,7 @@ void CPlaneWarView::OnTimer(UINT_PTR nIDEvent)
}
else {
//没出界,绘制
enemy->Draw(&cdc, passNum, FALSE);
enemy->Draw(&cdc, 1, FALSE);
}
}
......@@ -353,7 +327,7 @@ void CPlaneWarView::OnTimer(UINT_PTR nIDEvent)
CView::OnTimer(nIDEvent);
}
//键盘按下监听
void CPlaneWarView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
//按空格进入游戏
if (isStarted == FALSE) {
......@@ -364,7 +338,7 @@ void CPlaneWarView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
else {
if (myplane != NULL && GetKeyState(VK_SPACE) < 0) {
// 按空格键发射子弹
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y);
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage());
bulletList.AddTail(bullet);
}
}
......@@ -372,7 +346,7 @@ void CPlaneWarView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
}
//鼠标移动监听,控制战机位置
void CPlaneWarView::OnMouseMove(UINT nFlags, CPoint point)
void CAircraftBattleView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
......@@ -384,7 +358,7 @@ void CPlaneWarView::OnMouseMove(UINT nFlags, CPoint point)
}
//按下鼠标左键监听
void CPlaneWarView::OnLButtonDown(UINT nFlags, CPoint point)
void CAircraftBattleView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
......@@ -393,7 +367,7 @@ void CPlaneWarView::OnLButtonDown(UINT nFlags, CPoint point)
}
else if (myplane != NULL) {
// 按鼠标左键发射子弹
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y);
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage());
bulletList.AddTail(bullet);
}
......@@ -401,7 +375,7 @@ void CPlaneWarView::OnLButtonDown(UINT nFlags, CPoint point)
}
//鼠标右键监听
void CPlaneWarView::OnRButtonUp(UINT /* nFlags */, CPoint point)
void CAircraftBattleView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
if (isStarted == TRUE && myplane != NULL) {
// 按鼠标右键发射炮弹
......@@ -412,7 +386,7 @@ void CPlaneWarView::OnRButtonUp(UINT /* nFlags */, CPoint point)
//生命周期
//窗口销毁
void CPlaneWarView::OnDestroy()
void CAircraftBattleView::OnDestroy()
{