Commit cef65905 authored by CjhGm's avatar CjhGm
Browse files

final version

parent 5b0bc9b1
......@@ -30,7 +30,13 @@ END_MESSAGE_MAP()
CAircraftBattleDoc::CAircraftBattleDoc()
{
// TODO: 在此添加一次性构造代码
maxScore = 10;
CString fileName("data.txt");
CFile file(fileName, CFile::modeRead);
CArchive ar(&file, CArchive::load);
ar >> maxScore;
ar.Flush();
ar.Close();
file.Close();
}
CAircraftBattleDoc::~CAircraftBattleDoc()
......@@ -73,7 +79,7 @@ void CAircraftBattleDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
CString strText = _T("TODO: implement thumbnail drawing here");
LOGFONT lf;
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
pDefaultGUIFont->GetLogFont(&lf);
lf.lfHeight = 36;
......@@ -104,7 +110,7 @@ void CAircraftBattleDoc::SetSearchContent(const CString& value)
}
else
{
CMFCFilterChunkValueImpl *pChunk = NULL;
CMFCFilterChunkValueImpl* pChunk = NULL;
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
if (pChunk != NULL)
{
......@@ -135,4 +141,15 @@ void CAircraftBattleDoc::Dump(CDumpContext& dc) const
int CAircraftBattleDoc::getMaxScore() const {
return maxScore;
}
void CAircraftBattleDoc::setMaxScore(const int score) {
maxScore = score;
CString fileName("data.txt");
CFile file(fileName, CFile::modeCreate | CFile::modeWrite);
CArchive ar(&file, CArchive::store);
ar << maxScore;
ar.Flush();
ar.Close();
file.Close();
}
\ No newline at end of file
......@@ -34,6 +34,7 @@ protected:
public:
int getMaxScore() const;
void setMaxScore(const int score);
// 生成的消息映射函数
protected:
......
......@@ -68,10 +68,10 @@ BOOL CAircraftBattleView::PreCreateWindow(CREATESTRUCT& cs)
void CAircraftBattleView::OnDraw(CDC* pDC)
{
CAircraftBattleDoc* pDoc = GetDocument();
maxScore = pDoc->getMaxScore();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
maxScore = pDoc->getMaxScore();
// TODO: 在此处为本机数据添加绘制代码
}
......@@ -212,11 +212,10 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
HFONT textFont;
textFont = CreateFont(24, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(textFont);
cdc.SetTextColor(RGB(128, 128, 0));
const int space = 30, off = 150;
cdc.TextOutW(rect.right / 2 - off, 320, _T("方向控制:鼠标"));
cdc.TextOutW(rect.right / 2 - off, 320 + 1 * space, _T("射击:空格键、鼠标左键"));
cdc.TextOutW(rect.right / 2 - off, 320 + 2 * space, _T("暂停:Q键"));
cdc.SetTextColor(RGB(255, 255, 0));
const int space = 30, off = 200;
cdc.TextOutW(rect.right / 2 - off, 400, _T("方向控制:鼠标"));
cdc.TextOutW(rect.right / 2 - off, 400 + 1 * space, _T("射击:空格键、鼠标左键"));
}
else if (isStarted && !isOver) {
// 游戏界面
......@@ -472,13 +471,18 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2, str);
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 + 30, _T("再接再厉!"));
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 + 60, _T("是否重新开始?Y/N"));
maxScore = myScore;
CAircraftBattleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDoc->setMaxScore(maxScore);
}
else {
str.Format(_T("您的得分为:%d"), myScore);
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 - 30, str);
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2, _T("不要灰心!再来一次!"));
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 + 30, _T("是否重新开始?Y/N"));
maxScore = myScore;
}
}
......
......@@ -30,7 +30,7 @@ public:
//绘制
BOOL Draw(CDC* pDC, BOOL bPause);
//加载敌机图像
//加载子弹图像
static BOOL LoadImage();
};
......
......@@ -9,8 +9,7 @@
#define ENEMY_DAMAGE 1 // 敌机伤害
#define ENEMY_SCORE 10 // 敌机分数
class CEnemy : public CPlane
{
class CEnemy : public CPlane {
private:
int score;
int index;
......
......@@ -2,8 +2,7 @@
#include "afx.h"
class CGameObject : public CObject
{
class CGameObject : public CObject {
public:
CGameObject(int x = 0, int y = 0);
virtual ~CGameObject();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment