summaryrefslogtreecommitdiff
path: root/dbox.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2011-05-04 11:02:52 +0000
committerIan C <ianc@noddybox.co.uk>2011-05-04 11:02:52 +0000
commit30717a1d099e33572dd33bce3cc2ba9b4efb500c (patch)
tree6b32c3be36ffb1813678baff7fd5f3e6768c0240 /dbox.c
parent5efe1840d4868b4e993b54f8402ead7a3aa68681 (diff)
Added route display to play mode.
Diffstat (limited to 'dbox.c')
-rw-r--r--dbox.c94
1 files changed, 76 insertions, 18 deletions
diff --git a/dbox.c b/dbox.c
index 4dbb4f6..6fe8fd5 100644
--- a/dbox.c
+++ b/dbox.c
@@ -1106,9 +1106,24 @@ static void Solve(const level_t *p_level, route_t p_route,
/* ---------------------------------------- INTERACTIVE MODE
*/
+static int StateDepth(const state_t *p_state)
+{
+ int depth = 0;
+
+ while(p_state)
+ {
+ depth++;
+ p_state = p_state->parent;
+ }
+
+ return depth;
+}
+
+
static void CursesDisplay(const level_t *p_level,
const state_t *p_state,
- int play)
+ int p_play,
+ const route_t p_route)
{
char allow[80];
int x;
@@ -1173,7 +1188,7 @@ static void CursesDisplay(const level_t *p_level,
mvaddstr(p_level->height + 11, 0, allow);
- if (!play)
+ if (!p_play)
{
if (p_state->path)
{
@@ -1186,15 +1201,28 @@ static void CursesDisplay(const level_t *p_level,
}
else
{
- int depth = 0;
+ int d;
+
+ d = StateDepth(p_state);
- while(p_state)
+ if (d == MAX_ROUTE)
{
- depth++;
- p_state = p_state->parent;
+ mvprintw(p_level->height + 10, 0, "Depth: MAX");
+ }
+ else
+ {
+ mvprintw(p_level->height + 10, 0, "Depth: %d ", d);
}
- mvprintw(p_level->height + 10, 0, "Depth: %d ", depth);
+ if (strlen(p_route) > COLS-6)
+ {
+ mvprintw(p_level->height + 9, 0, "Route:%*.*s...",
+ COLS-10, COLS-10, p_route);
+ }
+ else
+ {
+ mvprintw(p_level->height + 9, 0, "Route:%s ", p_route);
+ }
}
mvprintw(LINES - 3, 0, "Last reason: %-40.40s", NoMoveReason(NULL));
@@ -1203,13 +1231,13 @@ static void CursesDisplay(const level_t *p_level,
}
-static void Interactive(const level_t *p_level, int play)
+static void Interactive(const level_t *p_level, int p_play)
{
int quit;
- route_t route;
+ route_t route = {0};
state_t *s;
- if (!play)
+ if (!p_play)
{
Solve(p_level, route, MAX_ROUTE, TRUE);
}
@@ -1230,9 +1258,9 @@ static void Interactive(const level_t *p_level, int play)
mvaddstr(LINES-1,0,"Cursors to move, P to follow path, "
"Q to quit, Backspace/B to step back");
- if (!play)
+ if (!p_play)
{
- if (route[0])
+ if (route[0])
{
if (strlen(route) > COLS-6)
{
@@ -1247,7 +1275,7 @@ static void Interactive(const level_t *p_level, int play)
else
{
mvprintw(p_level->height + 9, 0, "Route: None found -- "
- "level possibly impossible");
+ "level possibly impossible");
}
}
@@ -1255,7 +1283,7 @@ static void Interactive(const level_t *p_level, int play)
{
int key;
- CursesDisplay(p_level, s, play);
+ CursesDisplay(p_level, s, p_play, route);
key = getch();
@@ -1290,53 +1318,78 @@ static void Interactive(const level_t *p_level, int play)
if (s->parent)
{
s = s->parent;
+
+ if (p_play)
+ {
+ route[StateDepth(s) - 1] = 0;
+ }
}
break;
case KEY_LEFT:
- if (play && !s->left)
+ if (p_play && !s->left && StateDepth(s) < MAX_ROUTE)
{
s->left = CreateState(DIR_LEFT, FALSE, p_level, s, TRUE);
}
if (s->left)
{
+ if (p_play)
+ {
+ route[StateDepth(s) - 1] = 'L';
+ }
+
s=s->left;
}
break;
case KEY_RIGHT:
- if (play && !s->right)
+ if (p_play && !s->right && StateDepth(s) < MAX_ROUTE)
{
s->right = CreateState(DIR_RIGHT, FALSE, p_level, s, TRUE);
}
if (s->right)
{
+ if (p_play)
+ {
+ route[StateDepth(s) - 1] = 'R';
+ }
+
s = s->right;
}
break;
case KEY_DOWN:
- if (play && !s->down)
+ if (p_play && !s->down && StateDepth(s) < MAX_ROUTE)
{
s->down = CreateState(DIR_DOWN, FALSE, p_level, s, TRUE);
}
if (s->down)
{
+ if (p_play)
+ {
+ route[StateDepth(s) - 1] = 'D';
+ }
+
s = s->down;
}
break;
case KEY_UP:
- if (play && !s->up)
+ if (p_play && !s->up && StateDepth(s) < MAX_ROUTE)
{
s->up = CreateState(DIR_UP, FALSE, p_level, s, TRUE);
}
if (s->up)
{
+ if (p_play)
+ {
+ route[StateDepth(s) - 1] = 'U';
+ }
+
s = s->up;
}
break;
@@ -1352,6 +1405,11 @@ static void Interactive(const level_t *p_level, int play)
}
endwin();
+
+ if (p_play)
+ {
+ printf("Route = '%s'\n",route);
+ }
}