Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jiahan Cao
Aircraft-Battle
Commits
cef65905
Commit
cef65905
authored
Jun 16, 2019
by
CjhGm
Browse files
final version
parent
5b0bc9b1
Changes
10
Hide whitespace changes
Inline
Side-by-side
AircraftBattle/PlaneWar/AircraftBattleDoc.cpp
View file @
cef65905
...
...
@@ -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
AircraftBattle/PlaneWar/AircraftBattleDoc.h
View file @
cef65905
...
...
@@ -34,6 +34,7 @@ protected:
public:
int
getMaxScore
()
const
;
void
setMaxScore
(
const
int
score
);
// 生成的消息映射函数
protected:
...
...
AircraftBattle/PlaneWar/AircraftBattleView.cpp
View file @
cef65905
...
...
@@ -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
;
}
}
...
...
AircraftBattle/PlaneWar/CBullet.h
View file @
cef65905
...
...
@@ -30,7 +30,7 @@ public:
//绘制
BOOL
Draw
(
CDC
*
pDC
,
BOOL
bPause
);
//加载
敌机
图像
//加载
子弹
图像
static
BOOL
LoadImage
();
};
...
...
AircraftBattle/PlaneWar/CEnemy.h
View file @
cef65905
...
...
@@ -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
;
...
...
AircraftBattle/PlaneWar/GameObject.h
View file @
cef65905
...
...
@@ -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
();
...
...
AircraftBattle/PlaneWar/data.txt
View file @
cef65905
No preview for this file type
AircraftBattle/PlaneWar/image/start.bmp
View replaced file @
5b0bc9b1
View file @
cef65905
163 KB
|
W:
|
H:
33.7 KB
|
W:
|
H:
2-up
Swipe
Onion skin
AircraftBattle/PlaneWar/image/start.jpg
0 → 100644
View file @
cef65905
22 KB
AircraftBattle/PlaneWar/image/start1.bmp
View replaced file @
5b0bc9b1
View file @
cef65905
927 KB
|
W:
|
H:
15.9 KB
|
W:
|
H:
2-up
Swipe
Onion skin
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment