-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzff_main_ch.cpp
More file actions
executable file
·407 lines (396 loc) · 8.15 KB
/
zff_main_ch.cpp
File metadata and controls
executable file
·407 lines (396 loc) · 8.15 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
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
/*
LanGongINC
LanGongDEV
Copyright 2020 LanGongINC
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include"get.cpp"
// #include"rand.cpp"
#include<curses.h>
#include <unistd.h>
// #include <signal.h>
// #include <termios.h>
// #include <string.h>
// #include <unistd.h>
// #include <fcntl.h>
#include "getkeyboard.cpp"
using namespace std;
typedef const int ci;
typedef const char cc;
typedef const double cd;
// int kfd = 0;
// struct termios cooked, raw;
cc fu='F',you='H';
int tr,kd,fx,fy,hx,hy,s=0;
int sysE;
int keyboard()
{
// return getchar();
// if(read(kfd, &c, 1) < 0)
// {
// perror("read():");
// exit(-1);
// }
//
// switch(c)
// {
// case KEYCODE_L:
// // printf("LEFT\n");
// return 75;
// break;
// case KEYCODE_R:
// // printf("RIGHT\n");
// return 77;
// break;
// case KEYCODE_U:
// // printf("UP\n");
// return 72;
// break;
// case KEYCODE_D:
// // printf("DOWN\n");
// return 80;
// break;
// default:
// // printf("value: %c = 0x%02X = %d\n", c, c, c);
// }
return key::getkey();
}
void syscls()
{
system("clear");
}
int check(int num){
if(num==72||num=='w'||num=='W')return 1;
if(num==80||num=='s'||num=='S')return 2;
if(num==75||num=='a'||num=='A')return 3;
if(num==77||num=='d'||num=='D')return 4;
if(num==10)return 13;
if(num==114)return 7;
if(num==112)return 8;
if(num==113)return 9;
if(num==27)return 27;
else return 0;
}
ci nx[5]={0,-1,1,0,0};//sxzy
ci ny[5]={0,0,0,-1,1};
int n,field[10005][10005];
int level;
string name;
/*
//This is for pause
bool getpalse(){
int typeU;
fstream file;
file.open("palseZ.dll", ios::in);
streambuf* stream_buffer_cout = cout.rdbuf();
streambuf* stream_buffer_cin = cin.rdbuf();
streambuf* stream_buffer_file = file.rdbuf();
cin.rdbuf(stream_buffer_file);
cin>>typeU;
cin.rdbuf(stream_buffer_cin);
file.close();
if(typeU==1){
fstream file;
file.open("palseF.dll", ios::in);
streambuf* stream_buffer_cout = cout.rdbuf();
streambuf* stream_buffer_cin = cin.rdbuf();
streambuf* stream_buffer_file = file.rdbuf();
cin.rdbuf(stream_buffer_file);
cin>>n>>hx>>hy>>fx>>fy;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>field[i][j];
}
}
cin.rdbuf(stream_buffer_cin);
file.close();
return true;
}
return false;
}
void putpalse(){
fstream file;
file.open("palseZ.dll", ios::out);
streambuf* stream_buffer_cout = cout.rdbuf();
streambuf* stream_buffer_cin = cin.rdbuf();
streambuf* stream_buffer_file = file.rdbuf();
cout.rdbuf(stream_buffer_file);
syscls();
cout<<1;
cout.rdbuf(stream_buffer_cout);
file.close();
if(1==1){
fstream file;
file.open("palseF.dll", ios::out);
streambuf* stream_buffer_cout = cout.rdbuf();
streambuf* stream_buffer_cin = cin.rdbuf();
streambuf* stream_buffer_file = file.rdbuf();
cout.rdbuf(stream_buffer_file);
syscls();
cout<<n<<hx<<hy<<fx<<hy<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<field[i][j]<<" ";
}
cout<<endl;
}
cout.rdbuf(stream_buffer_cout);
file.close();
}
}
//This is for pause
*/
void maken(){
putlevel(0);
level=getlevel();
putboot(1);
printf("欢迎您来到 撞FuFu游戏 本游戏由LanGongDEV出品\n");
sleep(1);
printf("请设定一个用户名:\n");
string UserNameSET;
getline(cin,UserNameSET);
putuser(UserNameSET);
printf("设置完成\n");
sleep(1);
syscls();
sleep(1);
}
int start(){
// system("color F0");
system("clear");
printf("\n\n\n LanGongINC \n LanGongDEV \n");
sleep(3);
system("clear");
printf("欢迎\n");
level=getlevel();
system("clear");
printf(" 撞Fufu \n\n\n\n\n\n\n\n\n\n 欢迎!\n");
sleep(3);
if(level==-1||getboot()!=1){
maken();
}
system("clear");
printf(" 欢迎 ");
level=getlevel();
name=getuser();
cout<<name<<endl;
printf(" 您的等级%d\n\n\n\n",level);
printf(" ---推荐使用英文输入---\n");
sleep(2);
if(level==-1){
return 1;
}
else return 0;
}
int game(){
s=0;
while(true){
if(fx==hx&&fy==hy){
putlevel(level+1);
system("clear");
printf("恭喜您胜利!您的等级:%d\n继续游戏?[继续:Enter / 退出:q ]\n",level+1);
while(1){
int r=check(keyboard());
if(r==9)return 0;
else if(r==13)return 1;
else{
printf("------ERR4: 输入错误 请重新输入------\n");
}
}
}
system("clear");
for(int i=1;i<=n;i++){
for(int j=0;j<27-n;j++){
cout<<" ";
}
for(int j=1;j<=n;j++){
if(field[i][j]==0)cout<<" ";
if(field[i][j]==1)cout<<"-";
if(field[i][j]==2)cout<<"|";
if(field[i][j]==5)cout<<"H";
if(field[i][j]==6)cout<<"F";
}
cout<<endl;
}
printf("\n按上下左右键控制小人H,按‘R’键重新开始游戏,\n按‘Q’退出游戏\n");
int r=check(keyboard());
// printf("%d\n",r);
// sleep(1);
if(r==224||r==-32)continue;
if(r==7){
syscls();
return 1;
}
if(r==9){
syscls();
return 0;
}
if(r!=1 && r!=2 && r!=3 && r!=4 && r!=0 && r!=27){
system("clear");
printf("------ERR4: 输入错误 请重新输入------\n");
printf("%d",r);
sleep(1);
syscls();
continue;
}
if(r>0&&r<5){
//move
system("clear");
if(hx+nx[r]<=1||hx+nx[r]>n-1||hy+ny[r]<=1||hy+ny[r]>n-1){
printf("----------ERR1: 出界----------\n");
sleep(0.1);
continue;
}
if(field[hx+nx[r]][hy+ny[r]]==6){
putlevel(level+1);
syscls();
printf("恭喜您胜利!您的等级:%d\n继续游戏?[继续:Enter / 退出:q ]\n",level+1);
int r=check(keyboard());
while(1){
int r=check(keyboard());
if(r==9)return 0;
else if(r==13)return 1;
else{
printf("------ERR4: 输入错误 请重新输入------\n");
}
}
}
if(field[hx+nx[r]][hy+ny[r]]==0){
hx=hx+nx[r];
hy=hy+ny[r];
field[hx][hy]=5;
field[hx-nx[r]][hy-ny[r]]=0;
}
}
if(s>=level+5){
s=0;
continue;
}
int but[5];
memset(but,0,sizeof(but));
for(int i=1;i<=4;i++){
if(fx+nx[i]<=1||fx+nx[i]>n-1||fy+ny[i]<=1||fy+ny[i]>n-1){
but[i]=1;
}
if(field[fx+nx[i]][fy+ny[i]]!=0){
but[i]=1;
}
}
int tx=fx,ty=fy;
if(hx<fx&&but[2]==0){
fx+=nx[2];
fy+=ny[2];
}
else if(hx>fx&&but[1]==0){
fx+=nx[1];
fy+=ny[1];
}
else if(hy<fy&&but[4]==0){
fx+=nx[4];
fy+=ny[4];
}
else if(hy>fy&&but[3]==0){
fx+=nx[3];
fy+=ny[3];
}
else{
if(but[1]==0){
fx+=nx[1];
fy+=ny[1];
}
else if(but[2]==0){
fx+=nx[2];
fy+=ny[2];
}
else if(but[3]==0){
fx+=nx[3];
fy+=ny[3];
}
else if(but[4]==0){
fx+=nx[4];
fy+=ny[4];
}
}
field[fx][fy]=6;
field[tx][ty]=0;
s++;
}
}
void start_game(){
syscls();
memset(field,0,sizeof(field));
if(level<=10){
n=10,tr=24,kd=40;
}
else if(level<=20){
n=12,tr=34,kd=66;
}
else if(level>20){
n=15,tr=50,kd=119;
}
/*
0:_
1:-
2:|
5:H
6:F
*/
field[1][1]=field[n][n]=1;
field[1][n]=field[n][1]=1;
for(int i=2;i<=n-1;i++){
field[1][i]=field[n][i]=1;
field[i][1]=field[i][n]=2;
}
// for(int i=2;i<=n-1;i++){
// for(int j=2;j<=n-1;j++){
// while(true){
// int k=rand();
// if(k==0&&kd>0){
// break;
// }
// }
// }
// }
//printf("NIHAO\n");
level=getlevel();
fx=n-1,fy=n-1,hx=2,hy=2;
field[2][2]=5,field[n-1][n-1]=6;
if(game()==1)start_game();
}
/*
//This is for pause
void findpalse(){
if(getpalse()){
game();
}
else{
start_game();
}
}
//This is for pause
*/
//This is for not pause
void findpalse(){
start_game();
}
//This is for not pause
void goodbye(){
system("clear");
printf("\n 再见!\n\n\n\n\n LanGongINC\n LanGongDEV\n");
sleep(1);
system("clear");
}
int main(){
if(start()){
printf("--------ERR3: start error--------\n");
return -3;
exit(-3);
}
sleep(1);
findpalse();
goodbye();
return 0;
}