@@ -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;
3032void 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
3638void 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+
183194void 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+
216282int 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}
0 commit comments