文章

五十亿法郎的资金 | 小游戏

五十亿法郎的资金 | 小游戏

使用C++编写,运行在Windows系统控制台中的闯关小游戏。😀

一、游戏介绍🎮️

以二战为背景的闯关小游戏。纯C++编写。与之前的SpaceShip一样,在Windows7的环境下运行效果最好。 都是高二时候闲的写的。🫠

二、游戏内容🕹️

玩家通过键盘操纵游戏主人公。使用W、S、A、D来控制人物的四个方向上的移动;还有其他的操作可以在游戏中右侧的提示栏中找到。

每日辱法 (1/1) 🙃

代码

mian.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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>

using namespace std;

int x=1,y=1,bagx=1;
char input,output,bag[2][21]={"                    ",
							  "                    "};
HANDLE hOut;
COORD pos={0,0};

//文本
char text[3][1000]={"\n第一次世界大战后,\n\n法国为防德军入侵其东北边境。\n\n打算于1928年起开始构筑马奇诺防线。\n\n大量的钢筋混凝土和武器装备需要高昂的资金,\n\n而金库大门的钥匙却被总设计师弄丢了。\n",
					"你能帮助他找到钥匙并取来资金吗?",
					"\n你帮助法军找到了钥匙并获得了资金,共50亿法郎,\n\n并运用这笔资金建造了《不可以逾越》的防线——马奇诺防线。\n\n不久后,德军机械化部队绕过了马奇诺防线,\n\n出现在法国北部,世界上最坚固的防线也失守了。\n\n开战后的第42天,法国放弃了抵抗。\n\n50亿法郎如同风中的落叶,被无情地卷入黄沙之中......"};

//地图
char map1[1000][1000]={"####################        ++++++++++++++  ",
			           "#O#    ####    #####        + W:上       +  ",
			           "#   ##    ## ##### #        + S:下       +  ",
			  	       "# # #  ##   ##   # #        + A:左       +  ",
			           "# # ## ## # ## #   #        + D:右       +  ",
			           "# # #  #### ## # # #        + Q:拾取     +  ",
			           "#    ##   #    # # #        + O:背包(左) +  ",
			           "###     K  ####  #  ->      + P:背包(右) +  ",
			           "####################        ++++++++++++++  ",
			           "                    		                ",
				       "->>帮助法军找到金库的钥匙<<-                ",
				       "                                            ",
					   "----------背包----------                    ",
					   "|                      |                    ",
					   "|                      |                    ",
					   "--------------------------------------------",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "--------------------------------------------"},
					 
	 map2[1000][1000]={"####################        ++++++++++++++  ",
	 				   "# #       ##     #  >       + W:上       +  ",
	 				   "#   ## ##  # ### # #        + S:下       +  ",
	 				   "####   ###  ##  ## #        + A:左       +  ",
	 				   "# ## ###  # ##     #        + D:右       +  ",
	 				   "#    # ####    #####        + Q:拾取     +  ",
	 				   "# ###   #  ## ## $##        + O:背包(左) +  ",
	 				   "#O    #   ##     ###        + P:背包(右) +  ",
	 				   "####################        ++++++++++++++  ",
	 				   "                        	                ",
					   "---->>帮助法军取走资金<<----                ",
					   "                                            ",
					   "----------背包----------                    ",
					   "|                      |                    ",
					   "|                      |                    ",
					   "--------------------------------------------",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "|                                          |",
					   "--------------------------------------------"};

//刷新屏幕
void FLASH(int y,char map[1000][1000])
{
	pos={0,0};
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut,pos);
	
	for(int i=0;i<=y;i++)
		puts(map[i]);
	
	pos={1,13};
	SetConsoleCursorPosition(hOut,pos);
	
	for(int i=0;i<=1;i++)
		puts(bag[i]);
	
	pos={1,16};
	SetConsoleCursorPosition(hOut,pos);
	
	if(bag[0][bagx-1]=='B')
	{
		cout<<"    亲爱的士兵,你好。我是马奇诺防线的总"<<endl
			<<"|  设计师。在一个金库里有防线的启动资金,"<<endl
			<<"|  但我弄丢了钥匙,你能帮我找到并打开"<<endl
			<<"|  金库的大门吗?";
	}
	if(bag[0][bagx-1]=='K')
	{
		cout<<"法军金库的钥匙";
	}
	if(bag[0][bagx-1]=='$')
	{
		cout<<"建造马奇诺防线的启动资金";
	}
}

//输入检测
int ACTION(char map[1000][1000])
{
	input=getch();
	if(input=='d')
	{
		if(map[y][x+1]==' ')
		{
			map[y][x]=' ';
			x=x+1;
			map[y][x]='O';
		}
		else if(map[y][x+1]=='-')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='K')
				{
					map[y][x]=' ';
					x=x+1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得钥匙进入金库。                 ";
		}
		else if(map[y][x+1]=='>')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='$')
				{
					map[y][x]=' ';
					x=x+1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得金库中的资金。                 ";
		}
	}
	else if(input=='a')
	{
		if(map[y][x-1]==' ')
		{
			map[y][x]=' ';
			x=x-1;
			map[y][x]='O';
		}
		else if(map[y][x-1]=='-')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='K')
				{
					map[y][x]=' ';
					x=x-1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得钥匙进入金库。                 ";
		}
		else if(map[y][x+1]=='>')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='$')
				{
					map[y][x]=' ';
					x=x-1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得金库中的资金。                 ";
		}
	}
	else if(input=='w')
	{
		if(map[y-1][x]==' ')
		{
			map[y][x]=' ';
			y=y-1;
			map[y][x]='O';
		}
		else if(map[y-1][x]=='-')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='K')
				{
					map[y][x]=' ';
					y=y-1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得钥匙进入金库。                 ";
		}
		else if(map[y][x+1]=='>')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='$')
				{
					map[y][x]=' ';
					y=y-1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得金库中的资金。                 ";
		}
	}
	else if(input=='s')
	{
		if(map[y+1][x]==' ')
		{
			map[y][x]=' ';
			y=y+1;
			map[y][x]='O';
		}
		else if(map[y+1][x]=='-')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='K')
				{
					map[y][x]=' ';
					y=y+1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得钥匙进入金库。                 ";
		}
		else if(map[y][x+1]=='>')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]=='$')
				{
					map[y][x]=' ';
					y=y+1;
					map[y][x]='O';
					return 1;
				}
			}	
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"你还没有获得金库中的资金。                 ";
		}
	}
	else if(input=='p')
	{
		if(bagx+1==23)
		{
			bag[1][bagx]=' ';
			bagx=1;
			bag[1][bagx]='^';
		}	
		else
		{
			bag[1][bagx]=' ';
			bagx++;
			bag[1][bagx]='^';
		}	
	}
	else if(input=='o')
	{
		if(bagx-1==0)
		{
			bag[1][bagx]=' ';
			bagx=22;
			bag[1][bagx]='^';
		}	
		else
		{
			bag[1][bagx]=' ';
			bagx--;
			bag[1][bagx]='^';
		}	
	}
	else if(input=='q')
	{
		if(map[y+1][x]!=' '&&map[y+1][x]!='#')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]==' ')
				{
					bag[0][i]=map[y+1][x];
					map[y+1][x]=' ';
					return 0;
				}
			}
		}
		else if(map[y-1][x]!=' '&&map[y-1][x]!='#')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]==' ')
				{
					bag[0][i]=map[y-1][x];
					map[y-1][x]=' ';
					return 0;
				}
			}
		}
		else if(map[y][x+1]!=' '&&map[y][x+1]!='#')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]==' ')
				{
					bag[0][i]=map[y][x+1];
					map[y][x+1]=' ';
					return 0;
				}
			}
		}
		else if(map[y][x-1]!=' '&&map[y][x-1]!='#')
		{
			for(int i=0;i<=20;i++)
			{
				if(bag[0][i]==' ')
				{
					bag[0][i]=map[y][x-1];
					map[y][x-1]=' ';
					return 0;
				}
			}
		}
		else
		{
			pos={1,22};
			SetConsoleCursorPosition(hOut,pos);
			cout<<"没有可以获得的物品。                 ";
		}
	}
	return 0;
}

//延时 
void Delay(int   time)
{ 
	clock_t now=clock(); 
	while(clock()-now<time); 
} 

//开头
int BEGIN()
{
	while(1)
	{
		cout<<endl<<endl
			<<"          ------------------"<<endl
			<<"          |                |"<<endl
			<<"          | 50亿法郎的资金 |"<<endl
			<<"          |                |"<<endl
			<<"          ------------------"<<endl
			<<"                                   "<<endl
			<<"       开始游戏:S    推出游戏:Q  "<<endl;
		input=getch();
		if(input=='s')
			break;
		if(input=='q')
			return 0;
	}
	system("cls");
	for(int i=0;i<5;i++)
	{
		cout<<".";
		Sleep(100);
	}
	cout<<endl;
	for(int i=0;i<=168;i++)
	{
		cout<<text[0][i];
		Sleep(50);
	}
	cout<<endl;
	for(int i=0;i<5;i++)
	{
		cout<<".";
		Sleep(100);
	}
	cout<<endl<<endl;
	for(int i=0;i<=32;i++)
	{
		cout<<text[1][i];
		Sleep(50);
	}
	cout<<endl<<endl<<"按任意键继续...";
	while(1)
	{
		if(_kbhit())
		{
			getch();
			break;
		}
	}	
	return 1;
}
//279
//结尾
int END()
{
	system("cls");
	for(int i=0;i<5;i++)
	{
		cout<<".";
		Sleep(100);
	}
	cout<<endl;
	for(int i=0;i<=279;i++)
	{
		cout<<text[2][i];
		Sleep(50);
	}
	cout<<endl<<endl<<"按任意键继续...";
	while(1)
	{
		if(_kbhit())
		{
			getch();
			break;
		}
	}	
	system("cls");
	return 0;
}
int main()
{
	SetConsoleTitle("51亿法郎的资金");
	while(1)
	{
		int n;
		n=BEGIN();
		if(n==0)
			return 0;
		bag[0][0]='B';
		bag[1][0]='|';
		bag[1][1]='^';
		FLASH(21,map1);
		while(1)
		{
			output=ACTION(map1);
			FLASH(21,map1);
			if(output==1)
			{
				x=1;
				y=7;
				FLASH(21,map2);
				while(1)
				{
					output=ACTION(map2);
					FLASH(21,map2);
					if(output==1)
						break;
				}
				break;
			}
		}
		END();
		Sleep(2000);
	}
}


当时写的代码真是没眼看,不过游戏效果看起来还不错。🫢 这个游戏和之前那个SpaceShip都是当时用Dev-Cpp写的,后来复制到VS里有个别地方编译不过;只要照着提示修改一下就好,不是什么大问题。😶

本文由作者按照 CC BY 4.0 进行授权