2020-02-15 20:01:48 +00:00
|
|
|
//See $LK,"TextBase Layer",A="HI:TextBase Layer"$.
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
#define ATTR (BLACK << 12 + WHITE << 8)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
U32 text[TEXT_ROWS][TEXT_COLS];
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
U0 DrawIt(CTask *task, CDC *)
|
2020-02-16 05:49:44 +00:00
|
|
|
{ //$LK,"gr.text_base",A="MN:CGrGlobals"$ gets clear 60fps, so we must use our own permanent text array.
|
2020-12-23 23:27:18 +00:00
|
|
|
MemCopy(gr.text_base + TEXT_COLS, text, (TEXT_ROWS - 1) * TEXT_COLS * sizeof(U32));
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
// You can copy it this way, if you like:
|
2020-12-23 23:27:18 +00:00
|
|
|
// I64 i, j;
|
|
|
|
// for (j = 0; j < TEXT_ROWS; j++)
|
|
|
|
// for (i = 0; i < TEXT_COLS; i++)
|
|
|
|
// TextChar(task,, i, j, text[j][i]);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
Rename abs_addres to abs_address.
Update documentation/comments to rename addr, fun, var, stmt, blk, desc, reg, seg, ptr, dup, clus, val, and bttn, to address, function, variable, statement, block, description, register, segment, pointer, duplicate, cluster, value, and button, respectively.
2021-10-07 02:35:32 +01:00
|
|
|
TextPrint(task, 0, 0, ATTR >> 8, "Draw a maze with left button.");
|
2020-12-23 23:27:18 +00:00
|
|
|
TextPrint(task, 0, 1, ATTR >> 8, "Solve maze starting at right click.");
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 01:19:05 +00:00
|
|
|
#define STACK_SIZE 2048
|
Rename abs_addres to abs_address.
Update documentation/comments to rename addr, fun, var, stmt, blk, desc, reg, seg, ptr, dup, clus, val, and bttn, to address, function, variable, statement, block, description, register, segment, pointer, duplicate, cluster, value, and button, respectively.
2021-10-07 02:35:32 +01:00
|
|
|
//We would put these as local variables
|
2020-02-16 01:19:05 +00:00
|
|
|
//in SolveMaze() but the system stack size
|
2020-03-01 01:59:50 +00:00
|
|
|
//is limited, so it's a bad habit. The heap
|
2021-07-02 00:53:42 +01:00
|
|
|
//is the normal ZealOS technique, but
|
2020-02-15 20:01:48 +00:00
|
|
|
//it's a pain in this case.
|
2020-12-23 23:27:18 +00:00
|
|
|
I64 stack_ptr, stack_x [STACK_SIZE],
|
|
|
|
stack_y [STACK_SIZE],
|
2020-02-20 23:40:10 +00:00
|
|
|
stack_dir[STACK_SIZE];
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
//Four directions:
|
2020-12-23 23:27:18 +00:00
|
|
|
// 0=Up, 1=right,2=down,3=left
|
|
|
|
I64 dir_x[4] = { 0, +1, 0, -1}, // Could use $LK,"gr_x_offsets2",A="MN:gr_x_offsets2"$,$LK,"gr_y_offsets2",A="MN:gr_y_offsets2"$
|
|
|
|
dir_y[4] = {+1, 0, -1, 0};
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
U0 SolveMaze(I64 x, I64 y)
|
2020-02-15 20:01:48 +00:00
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
I64 dir = 0;
|
|
|
|
|
|
|
|
stack_ptr = 0;
|
|
|
|
stack_x[stack_ptr] = x;
|
|
|
|
stack_y[stack_ptr] = y;
|
|
|
|
stack_dir[stack_ptr++] = dir;
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (!(0 <= x < MinI64(Fs->win_width, TEXT_COLS)) ||
|
|
|
|
!(0 <= y < MinI64(Fs->win_height, TEXT_ROWS)) )
|
|
|
|
{
|
|
|
|
Beep;
|
|
|
|
Beep;
|
2020-02-20 23:40:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!text[y][x].u8[0])
|
2020-12-23 23:27:18 +00:00
|
|
|
text[y][x] = '.' + ATTR;
|
|
|
|
x += dir_x[dir];
|
|
|
|
y += dir_y[dir];
|
2020-02-15 20:01:48 +00:00
|
|
|
//u8.[0] is the ASCII
|
2020-12-23 23:27:18 +00:00
|
|
|
if (text[y][x].u8[0])
|
|
|
|
{
|
|
|
|
x -= dir_x[dir];
|
|
|
|
y -= dir_y[dir];
|
|
|
|
if (++dir == 4)
|
|
|
|
{
|
|
|
|
if (--stack_ptr < 0)
|
|
|
|
return;
|
|
|
|
x = stack_x[stack_ptr];
|
|
|
|
y = stack_y[stack_ptr];
|
|
|
|
dir = stack_dir[stack_ptr];
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-12-23 23:27:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dir = 0;
|
|
|
|
stack_x[stack_ptr] = x;
|
|
|
|
stack_y[stack_ptr] = y;
|
|
|
|
stack_dir[stack_ptr++] = dir;
|
|
|
|
if (stack_ptr == STACK_SIZE)
|
|
|
|
return;
|
2020-02-20 23:40:10 +00:00
|
|
|
Sleep(100);
|
2020-03-19 20:59:53 +00:00
|
|
|
if (CharScan)
|
2020-02-20 23:40:10 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 Maze()
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
I64 ch, x, y;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
|
|
|
AutoComplete;
|
|
|
|
WinBorder;
|
|
|
|
WinMax;
|
|
|
|
DocCursor;
|
|
|
|
DocClear;
|
2020-12-23 23:27:18 +00:00
|
|
|
Fs->draw_it = &DrawIt;
|
|
|
|
Fs->win_inhibit = WIG_TASK_DEFAULT - WIF_SELF_FOCUS - WIF_SELF_BORDER;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
try
|
2020-12-23 23:27:18 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
MemSet(text, 0, sizeof(text));
|
|
|
|
while (!(ch = CharScan))
|
|
|
|
{
|
|
|
|
x = mouse.pos_text.x - Fs->win_left - Fs->scroll_x / FONT_WIDTH;
|
|
|
|
y = mouse.pos_text.y - Fs->win_top - Fs->scroll_y / FONT_HEIGHT;
|
|
|
|
if (mouse.lb && !winmgr.grab_scroll)
|
|
|
|
text[y][x] = CH_SPACE + ATTRF_INVERT + ATTR;
|
|
|
|
if (mouse.rb && !winmgr.grab_scroll)
|
|
|
|
{
|
|
|
|
text[y][x] = '*'+ATTR;
|
|
|
|
SolveMaze(x, y);
|
|
|
|
ch = CharGet;
|
2020-02-20 23:40:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Refresh;
|
|
|
|
}
|
2020-12-23 23:27:18 +00:00
|
|
|
}
|
|
|
|
while (ch != CH_SHIFT_ESC && ch != CH_ESC);
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
catch
|
|
|
|
PutExcept;
|
|
|
|
SettingsPop;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Maze;
|