Skip to content

Commit 0437986

Browse files
committed
huge update
1 parent c9bbdeb commit 0437986

File tree

9 files changed

+209
-41
lines changed

9 files changed

+209
-41
lines changed

lib/checkdata.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@ bool checkdata ()
1818
return true;
1919
}
2020

21+
bool check_custom_data (char *name)
22+
{
23+
char *p;
24+
strcpy (p, "usr/custom/world/");
25+
strcat (p, name);
26+
strcat (p, "/main");
27+
struct stat buffer;
28+
if (stat (name, &buffer) != 0)
29+
{
30+
printf ("Cannot read data! Please check 'usr/custom/world' folder.\n");
31+
printf ("More info: https://github.com/ohzff/Zff-Reload/\n");
32+
return false;
33+
}
34+
return true;
35+
}
36+
2137
#endif

lib/move.hpp

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ inline int check(int num){
1717
if(num==113)return 9;
1818
if(num==27)return 27;
1919
if(num==32)return 32;
20+
if(num==127)return 127;
21+
if(num=='/')return num;
2022
if(num==224||num==-32||num == 91)return -1;
2123
return 0;
2224
}
@@ -30,7 +32,7 @@ pair <int, int> _w;
3032
void windowsize ()
3133
{
3234
_w = getWindow ();
33-
WINDOW_X = _w.first - 2, WINDOW_Y = _w.second;
35+
WINDOW_X = _w.first - 1, WINDOW_Y = _w.second;
3436
}
3537

3638
void windowsize_protect ()
@@ -180,6 +182,15 @@ void move_left_right (int t)
180182
}
181183
}
182184

185+
void update_pos ()
186+
{
187+
strcpy (BOTTOM_RIGHT_INFO, "(");
188+
strcat (BOTTOM_RIGHT_INFO, inttochar (x));
189+
strcat (BOTTOM_RIGHT_INFO, ", ");
190+
strcat (BOTTOM_RIGHT_INFO, inttochar (y));
191+
strcat (BOTTOM_RIGHT_INFO, ")");
192+
}
193+
183194
void allinone_protect ()
184195
{
185196
while (GAMEDIED == 0)
@@ -189,6 +200,8 @@ void allinone_protect ()
189200
if (! pos_legal (x, y)) stop ();
190201
if (x == ex && y == ey) win ();
191202

203+
update_pos ();
204+
192205
trigger_disable ();
193206
trigger_enable ();
194207

@@ -213,10 +226,65 @@ void jump ()
213226
ONJUMP = 0;
214227
}
215228

229+
void tokenize(std::string const &str, const char* delim,
230+
std::vector<std::string> &out)
231+
{
232+
char *token = strtok(const_cast<char*>(str.c_str()), delim);
233+
while (token != nullptr)
234+
{
235+
out.push_back(std::string(token));
236+
token = strtok(nullptr, delim);
237+
}
238+
}
239+
240+
void command ()
241+
{
242+
while (true)
243+
{
244+
int read = keyboard ();
245+
if (read == 27) return;
246+
if (read == 127)
247+
{
248+
BOTTOM_LEFT_INFO[strlen (BOTTOM_LEFT_INFO) - 1] = '\0';
249+
}
250+
else if ((read >= 'a' && read <= 'z') || (read >= '0' && read <= '9') || read == ' ')
251+
{
252+
char tmp[2] = {char (read)};
253+
strcat (BOTTOM_LEFT_INFO, tmp);
254+
}
255+
else if (read == 10)
256+
{
257+
string str (BOTTOM_LEFT_INFO);
258+
vector <string> arg;
259+
tokenize (str, " ", arg);
260+
if (arg[0] == "/pos")
261+
{
262+
if (arg.size () == 3)
263+
{
264+
int ix, iy;
265+
sscanf (arg[1].c_str (), "%d", &ix);
266+
sscanf (arg[2].c_str (), "%d", &iy);
267+
if (field[ix][iy].issafe () && pos_legal (ix, iy))
268+
{
269+
field[x][y].user = 0, field[ix][iy].user = 1;
270+
x = ix, y = iy;
271+
return;
272+
}
273+
}
274+
strcpy (BOTTOM_LEFT_INFO, "ERROR");
275+
msleep (OUTPUT_TIME * 1000);
276+
return;
277+
}
278+
}
279+
}
280+
}
281+
216282
int ctrl (int level)
217283
{
218284
x = sx, y = sy;
219285
ONJUMP = 0, GAMEDIED = 0, GAMEWIN = 0;
286+
memset (trig_status, 0, sizeof (trig_status));
287+
memset (trig_delay, 0, sizeof (trig_delay));
220288
strcpy (OUTPUT_RIGHT_INFO, "Level ");
221289
strcat (OUTPUT_RIGHT_INFO, inttochar (level));
222290

@@ -236,8 +304,9 @@ int ctrl (int level)
236304
int read;
237305
while (true)
238306
{
307+
strcpy (BOTTOM_LEFT_INFO, " Ready");
239308
read = 0;
240-
while ((read < 1 || read > 4) && read != 9 && read != 32)
309+
while ((read < 1 || read > 4) && read != 9 && read != 32 && read != '/')
241310
{
242311
read = check (keyboard ());
243312
// read = keyverify ();
@@ -248,6 +317,12 @@ int ctrl (int level)
248317
break;
249318
}
250319
}
320+
if (read == '/')
321+
{
322+
strcpy (BOTTOM_LEFT_INFO, " /");
323+
command ();
324+
}
325+
strcpy (BOTTOM_LEFT_INFO, " Working...");
251326
if (read == 3 || read == 4)
252327
{
253328
//left
@@ -262,13 +337,14 @@ int ctrl (int level)
262337
}
263338
if (read == 9)
264339
{
340+
strcpy (BOTTOM_LEFT_INFO, " Exit");
265341
stop (1);
266-
return 0;
342+
return -1;
267343
}
268344

269345
if (GAMEDIED == 1 || read == 114514)
270346
{
271-
return GAMEWIN;
347+
return GAMEWIN ? 0 : -1;
272348
}
273349
}
274350
}

lib/output.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ inline void output ()
112112
}
113113
else
114114
{
115-
wstartx = x - (WINDOW_X >> 1), wendx = WINDOW_X + wstartx - 1;
115+
wstartx = x - (WINDOW_X >> 1), wendx = WINDOW_X + wstartx - 3;
116116
wwaitx = 0;
117117
}
118118
if (WINDOW_Y >= m)
@@ -154,7 +154,14 @@ inline void output ()
154154
for (int j = 1; j <= WINDOW_Y; j ++) putchar (' ');
155155
putchar ('\n');
156156
}
157-
for (int i = 1; i <= WINDOW_Y; i ++) putchar (' ');
157+
// for (int i = 1; i <= WINDOW_Y; i ++) putchar (' ');
158+
printf ("%s", BOTTOM_LEFT_INFO);
159+
for (int i = strlen (BOTTOM_LEFT_INFO); i < WINDOW_Y - strlen (BOTTOM_RIGHT_INFO) - 1; i ++)
160+
{
161+
putchar (' ');
162+
}
163+
printf ("%s", BOTTOM_RIGHT_INFO);
164+
putchar ('\n');
158165
}
159166

160167

lib/readworld.hpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "struct-define.hpp"
66

77
const char readpath[100] = "usr/world/";
8+
const char custompath[100] = "usr/custom/world/";
89

910
// char charfield[1005][1005];
10-
string str;
11+
// string str;
1112

1213
char* inttochar (int x)
1314
{
@@ -16,29 +17,46 @@ char* inttochar (int x)
1617
return str;
1718
}
1819

19-
void read_world (int id)
20+
void read_world (int id, string custom = "")
2021
{
21-
printf ("Reading data from %d...\n", id);
22-
23-
memset (trigger, 0, sizeof (trigger));
24-
memset (field, 0, sizeof (field));
25-
triggerCount = 0, OUTPUT_STOP = 0;
26-
2722
char main_path[200] = "";
2823
char world_path[200] = "";
2924
char trigger_path[200] = "";
3025

31-
strcat (main_path, readpath);
32-
strcat (main_path, inttochar (id));
33-
strcat (main_path, "/main");
26+
if (id == -1)
27+
{
28+
strcat (main_path, custompath);
29+
strcat (main_path, custom.c_str ());
30+
strcat (main_path, "/main");
31+
32+
strcat (world_path, custompath);
33+
strcat (world_path, custom.c_str ());
34+
strcat (world_path, "/world");
35+
36+
strcat (trigger_path, custompath);
37+
strcat (trigger_path, custom.c_str ());
38+
strcat (trigger_path, "/trigger");
39+
}
40+
else
41+
{
42+
strcat (main_path, readpath);
43+
strcat (main_path, inttochar (id));
44+
strcat (main_path, "/main");
45+
46+
strcat (world_path, readpath);
47+
strcat (world_path, inttochar (id));
48+
strcat (world_path, "/world");
49+
50+
strcat (trigger_path, readpath);
51+
strcat (trigger_path, inttochar (id));
52+
strcat (trigger_path, "/trigger");
53+
}
3454

35-
strcat (world_path, readpath);
36-
strcat (world_path, inttochar (id));
37-
strcat (world_path, "/world");
55+
printf ("Reading data from...\n");
3856

39-
strcat (trigger_path, readpath);
40-
strcat (trigger_path, inttochar (id));
41-
strcat (trigger_path, "/trigger");
57+
memset (trigger, 0, sizeof (trigger));
58+
memset (field, 0, sizeof (field));
59+
triggerCount = 0, OUTPUT_STOP = 0;
4260

4361
printf ("%s\n", main_path);
4462
printf ("%s\n", world_path);

lib/struct-define.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Point
3737

3838
bool isfree ()
3939
{
40-
return user == 0 && trigger.size () == 0;
40+
return user == 0;
4141
}
4242

4343
bool issafe ()
@@ -63,7 +63,7 @@ Trigger trigger[inf * 10];
6363
bool trig_status[inf * 10];
6464
int trig_delay[inf * 10];
6565
int x, y;
66-
char OUTPUT_RIGHT_INFO[1000];
66+
char OUTPUT_RIGHT_INFO[1000], BOTTOM_LEFT_INFO[1000], BOTTOM_RIGHT_INFO[1000];
6767

6868
int OUTPUT_STOP = 0;
6969

lib/version.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef ZFFVER
2+
#define ZFFVER
3+
4+
void version_output ()
5+
{
6+
printf ("Zff Version 0.1 Beta\nMade by ohzff 5+1 <https://github.com/ohzff/Zff-Reload>.\n");
7+
}
8+
9+
#endif

main.cpp

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,71 @@ using namespace std;
1515
#include "lib/checkdata.hpp"
1616
#include "lib/output.hpp"
1717
#include "lib/move.hpp"
18+
#include "lib/version.hpp"
1819

19-
int main ()
20+
int readytorun (int &i)
2021
{
21-
if (! checkdata ())
22-
{
23-
return 1;
24-
}
22+
HIDE_CURSOR ();
23+
syscls ();
24+
25+
thread output_thread (dooutput);
26+
output_thread.detach ();
2527

26-
for (int i = 1; i <= 2; i ++)
28+
OUTPUT_STOP = 0, GAMEDIED = 0, GAMEWIN = 0;
29+
30+
int k = ctrl (i);
31+
if (k == -1) return 1;
32+
if (k != 0)
2733
{
28-
read_world (i);
34+
i = k - 1;
35+
}
2936

30-
HIDE_CURSOR ();
31-
syscls ();
37+
SHOW_CURSOR ();
38+
OUTPUT_STOP = 1;
39+
return 0;
40+
}
3241

33-
thread output_thread (dooutput);
34-
output_thread.detach ();
42+
int main (int argc, char * argv[])
43+
{
44+
if (! checkdata ())
45+
{
46+
return 1;
47+
}
3548

36-
OUTPUT_STOP = 0, GAMEDIED = 0, GAMEWIN = 0;
49+
int START = 1;
3750

38-
if (! ctrl (i)) break;
51+
if (argc > 1)
52+
{
53+
if (strcmp (argv[1], "level") == 0 && argc > 2)
54+
{
55+
char name[500];
56+
strcpy (name, argv[2]);
57+
sscanf (name, "%d", &START);
58+
printf ("Done.\n");
59+
}
60+
else if (strcmp (argv[1], "custom") == 0 && argc > 2)
61+
{
62+
if (check_custom_data (argv[2])) return 1;
63+
read_world (-1, string (argv[2]));
64+
int a = 0;
65+
readytorun (a);
66+
}
67+
else if (strcmp (argv[1], "version") == 0)
68+
{
69+
version_output ();
70+
return 0;
71+
}
72+
else
73+
{
74+
printf ("Command not found!\n");
75+
return 1;
76+
}
77+
}
3978

40-
SHOW_CURSOR ();
41-
OUTPUT_STOP = 1;
79+
for (int i = START; i <= 2; i ++)
80+
{
81+
read_world (i);
82+
if (readytorun (i)) break;
4283
}
4384
SHOW_CURSOR ();
4485
return 0;

usr/custom/world/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Keep the folder.

usr/world/2/world

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
|---------------------- ---||||||||||||||||||||||||||||||||||||||
88
|--- ------------ ---- ----- -------- |
99
|----* -------- ------ ----- -------- |
10-
|------- ------ -------- ----- -------- |
10+
|------- ---- -------- ----- -------- |
1111
|------------ ----------- ||||| |||||||| -----------|
1212
|--------------------*---------------------------------------------|
1313
| |

0 commit comments

Comments
 (0)