-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_Main_Window_function.cpp
More file actions
318 lines (269 loc) · 9.82 KB
/
Copy pathabout_Main_Window_function.cpp
File metadata and controls
318 lines (269 loc) · 9.82 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include "const_Value.h"
#include "about_Draw.h"
#include "about_class.h"
#include "about_operation.h"
using namespace std;
bool Main_Windows(HANDLE hOut,HWND hWnd)
{
//relevant card date
file_cardmessage.open("Card.txt");
if(!file_cardmessage.is_open())
{
MessageBox(NULL,"Lack the important date file!", "Error", MB_OK | MB_ICONEXCLAMATION);
exit(1);
}
//for game running
srand((unsigned int)time(0));
//creat Card and load the card message
vector<Card> card(NUMBER_CARD);
Load_Card_Message(file_cardmessage,card);
//draw the main interface
Draw_Main_Windows(hOut,hWnd);
//get current cursor position
GetConsoleScreenBufferInfo(hOut,&bInfo);
COORD now_pos={bInfo.dwCursorPosition.X,bInfo.dwCursorPosition.Y};
COORD choice_pos={MAIN_WINDOW_SELECT_POS_X_2,MAIN_WINDOW_SELECT_POS_Y_2};
Draw_Cursor_in_Main_Window_Select(choice_pos,hOut);
SetConsoleCursorPosition(hOut,choice_pos);
//get and respone the key event
while(1)
{
//direct change the choice_pos value and get the key event to temp_ope
if(_kbhit())
{
int temp_ope = Get_and_Respone_Key_Event_in_Main_Window(choice_pos,hOut);
if(temp_ope!=0)
{
switch (temp_ope)
{
case VK_RETURN:
goto SURE_CHOICE;
case VK_ESCAPE:
goto END_CHOICE;
}
}
}
}
SURE_CHOICE:;
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_1&&choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_1)
{
Display_Card_Message(card,hOut);
file_cardmessage.close();
return true;
}
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_2&&choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_2)
{
Draw_Tips_about_Freedom_Mode_Game(hOut);
while(1)
{
if(_kbhit())
{
_getch();
break;
}
}
while(1)
{
if(Play_Freedom_Mode_Game(file_battlefield,card,hOut)==false)
{
file_cardmessage.close();
return true;
}
}
}
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_3&&choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_3)
{
while(1)
{
//true mean continue play
//false mean back to main window
if(Play_Story_Mode_Game(card,hOut)==false)
{
file_cardmessage.close();
return true;
}
}
}
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_4&&choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_4)
{
Display_Number_Story(card,hOut);
file_cardmessage.close();
return true;
}
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_5&&choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_5)
{
END_CHOICE:;
//sure the exit operation
if(Exit_Game(hOut)==true)
{
file_cardmessage.close();
return false;
}
else
{
file_cardmessage.close();
return true;
}
}
}
bool Play_Freedom_Mode_Game(fstream &file_battlefield,vector<Card> &card,HANDLE hOut)
{
file_battlefield.open("FreedomModeMap.txt");
if(!file_battlefield.is_open())
{
MessageBox(NULL,"Lack the important date file!", "Error", MB_OK | MB_ICONEXCLAMATION);
exit(1);
}
Draw_Play_Freedom_Mode_Windows(hOut,hWnd);
file_battlefield.clear();
file_battlefield.seekg(0);
Draw_Freedom_Mode_Map(file_battlefield,hOut);
Battlefield _map;
_map.Load_Battlefield(file_battlefield);
Selectarea select[NUMBER_SELECT_CARD];
Home player_home(HOME_PLAYER_POS_X,HOME_PLAYER_POS_Y);
Home computer_home(HOME_COMPUTER_POS_X,HOME_COMPUTER_POS_Y);
Statue message[2];//record the statue about player and computer
bool win_player_or_computer=COMPUTER;
file_battlefield.close();
Game_Start(_map,select,card,player_home,computer_home,message,hOut);
if(Gaming(_map,select,card,player_home,computer_home,message,hOut,win_player_or_computer)==false)
return false;//direct quit to main window
//true mean continue play
//false mean back to main window
if(Game_End(win_player_or_computer,hOut)==true)
return true;
else
return false;
}
void Display_Card_Message(vector<Card> &card,HANDLE hOut)
{
Display_Card_Process(card,hOut);
}
void Display_Number_Story(vector<Card> &card,HANDLE hOut)
{
system("CLS");
Draw_Number_Story(hOut);
}
bool Play_Story_Mode_Game(vector<Card> &cards,HANDLE hOut)
{
fstream file_progress;
file_progress.open("StoryProgress.txt");
if(!file_progress.is_open())
{
MessageBox(NULL,"Lack the important date file!", "Error", MB_OK | MB_ICONEXCLAMATION);
exit(1);
}
unsigned short progress;
file_progress>>progress;
Play_Story_Mode_Process(progress,cards,hOut);
//Save the progress
file_progress.clear();
file_progress.seekg(0);
file_progress<<progress;
file_progress.close();
return false;
}
bool Exit_Game(HANDLE hOut)
{
if(MessageBox(NULL,"Do you really want to quit?", "Tip",MB_YESNO)==IDYES)
return true;
else
return false;
}
void Load_Card_Message(fstream &file_cardmessage,vector<Card> &card)
{
for(int n=0;n<NUMBER_CARD;n++)
card[n].Set_Card_Date(file_cardmessage);
}
int Get_and_Respone_Key_Event_in_Main_Window(COORD &choice_pos,HANDLE hOut)
{
int b=_getch();
if(b!=VK_ESCAPE&&b!=VK_RETURN&&b==224)
{
b=_getch();
switch(b)
{
case UP:
if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_1)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_5,MAIN_WINDOW_SELECT_POS_Y_5};
}
else if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_5)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_2,MAIN_WINDOW_SELECT_POS_Y_2};
}
//SetConsoleCursorPosition(hOut,choice_pos);
Draw_Cursor_in_Main_Window_Select(choice_pos,hOut);//in about_Draw_function.cpp
SetConsoleCursorPosition(hOut,choice_pos);
return 0;
case DOWN:
if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_1)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_5,MAIN_WINDOW_SELECT_POS_Y_5};
}
else if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_5)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_3,MAIN_WINDOW_SELECT_POS_Y_3};
}
//SetConsoleCursorPosition(hOut,choice_pos);
Draw_Cursor_in_Main_Window_Select(choice_pos,hOut);//in about_Draw_function.cpp
SetConsoleCursorPosition(hOut,choice_pos);
return 0;
case LEFT:
if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_1)
{
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_1)
choice_pos={MAIN_WINDOW_SELECT_POS_X_4,MAIN_WINDOW_SELECT_POS_Y_4};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_2)
choice_pos={MAIN_WINDOW_SELECT_POS_X_1,MAIN_WINDOW_SELECT_POS_Y_1};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_3)
choice_pos={MAIN_WINDOW_SELECT_POS_X_2,MAIN_WINDOW_SELECT_POS_Y_2};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_4)
choice_pos={MAIN_WINDOW_SELECT_POS_X_3,MAIN_WINDOW_SELECT_POS_Y_3};
}
else if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_5)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_1,MAIN_WINDOW_SELECT_POS_Y_1};
}
//SetConsoleCursorPosition(hOut,choice_pos);
Draw_Cursor_in_Main_Window_Select(choice_pos,hOut);//in about_Draw_function.cpp
SetConsoleCursorPosition(hOut,choice_pos);
return 0;
case RIGHT:
if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_1)
{
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_1)
choice_pos={MAIN_WINDOW_SELECT_POS_X_2,MAIN_WINDOW_SELECT_POS_Y_2};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_2)
choice_pos={MAIN_WINDOW_SELECT_POS_X_3,MAIN_WINDOW_SELECT_POS_Y_3};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_3)
choice_pos={MAIN_WINDOW_SELECT_POS_X_4,MAIN_WINDOW_SELECT_POS_Y_4};
else
if(choice_pos.X==MAIN_WINDOW_SELECT_POS_X_4)
choice_pos={MAIN_WINDOW_SELECT_POS_X_1,MAIN_WINDOW_SELECT_POS_Y_1};
}
else if(choice_pos.Y==MAIN_WINDOW_SELECT_POS_Y_5)
{
choice_pos={MAIN_WINDOW_SELECT_POS_X_4,MAIN_WINDOW_SELECT_POS_Y_4};
}
//SetConsoleCursorPosition(hOut,choice_pos);
Draw_Cursor_in_Main_Window_Select(choice_pos,hOut);//in about_Draw_function.cpp
SetConsoleCursorPosition(hOut,choice_pos);
return 0;
}
}
if(b==VK_RETURN)
{
return VK_RETURN;
}
if(b==VK_ESCAPE)
{
return VK_ESCAPE;
}
}