-
Notifications
You must be signed in to change notification settings - Fork 0
/
Russian Window.cpp
176 lines (168 loc) · 3.05 KB
/
Russian Window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <afxwin.h>
#include "Russian Class.h"
#define gamestop 0
#define gamestart 1
#define gameover -1
#define gameing 2
CMyApp Russian_Box;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainFrame;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_MOUSEWHEEL()
ON_WM_TIMER()
END_MESSAGE_MAP()
CMainFrame::CMainFrame()
{
gamestate = gamestop;
CRect WinRect(0, 0, 740, 715);
Create(NULL, _T("Russian Box"), WS_CAPTION | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_SYSMENU, WinRect);
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpcs)
{
if (CFrameWnd::OnCreate(lpcs) == -1) return -1;
if (!SetTimer(1, 1000, NULL)) return - 1;
return 0;
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this);
if (gamestate == gamestop)
{
GameInit();
gamestate = gamestart;
}
DrawGame();
DrawBox();
DrawNextBox();
CFont mFont;
mFont.CreatePointFont(140, _T("Arial"));
dc.SelectObject(&mFont);
dc.SetTextColor(RGB(40, 20, 60));
dc.DrawText(_T("copyright©lorain·lynies"), CRect(490, 300, 680, 350), DT_LEFT | DT_TOP);
dc.DrawText(_T("纯鼠标操作"), CRect(490, 350, 680, 400), DT_LEFT | DT_TOP);
dc.DrawText(_T("鼠标左键开始游戏"), CRect(490, 400, 680, 450), DT_LEFT | DT_TOP);
}
void CMainFrame::OnTimer(UINT nTimerID)
{
if (gamestate == gameing)
{
UnDrawBox();
tempbox.pos.y++;
if (BoxOk())
{
DrawBox();
}
else
{
tempbox.pos.y--;
DrawBox();
SaveBox();
if (ClearnLine()) DrawGame();
NewBox();
DrawBox();
}
}
if (gamestate == gameover)
{
KillTimer(1);
CString tempstr;
tempstr.Format(_T("score:%d"), score);
MessageBox(tempstr, _T("game over"), MB_OK);
GameInit();
DrawGame();
gamestate = gamestart;
SetTimer(1, 1000, NULL);
}
}
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
if (gamestate == gameing)
{
UnDrawBox();
tempbox.pos.x--;
if (!BoxOk()) tempbox.pos.x++;
DrawBox();
}
if (gamestate == gamestart)
{
gamestate = gameing;
}
}
void CMainFrame::OnLButtonDblClk(UINT nFlags, CPoint point)
{
int k = 2;
while (--k)
{
if (gamestate == gameing)
{
UnDrawBox();
tempbox.pos.x--;
if (!BoxOk()) tempbox.pos.x++;
DrawBox();
}
}
}
void CMainFrame::OnRButtonDown(UINT nFlags, CPoint point)
{
if (gamestate == gameing)
{
UnDrawBox();
tempbox.pos.x++;
if (!BoxOk()) tempbox.pos.x--;
DrawBox();
}
}
void CMainFrame::OnRButtonDblClk(UINT nFlags, CPoint point)
{
int k = 2;
while (--k)
{
if (gamestate == gameing)
{
UnDrawBox();
tempbox.pos.x++;
if (!BoxOk()) tempbox.pos.x--;
DrawBox();
}
}
}
BOOL CMainFrame::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
if (gamestate == gameing)
{
if (zDelta < 0)
{
UnDrawBox();
tempbox.pos.y++;
if (BoxOk())
{
DrawBox();
return TRUE;
}
else
{
tempbox.pos.y--;
DrawBox();
return TRUE;
}
}
else
{
UnDrawBox();
if (RollAble()) RollBox();
DrawBox();
}
}
return TRUE;
}