Skip to content

Commit

Permalink
Merge pull request #68 from cyborgdennett/master
Browse files Browse the repository at this point in the history
feat: Wrap around board edges when navigating with arrow keys
  • Loading branch information
jubalh authored Sep 5, 2024
2 parents 53d4f84 + 886d3e3 commit 44a55b9
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,51 +696,64 @@ int main(int argc, char *argv[])
{
case 'h':
case KEY_LEFT:
if(x>5)
if (x-GRID_NUMBER_START_X <= 0) {
x = GRID_NUMBER_START_X + GRID_LINE_DELTA*8;
}
else if(x>5)
{
x -= GRID_LINE_DELTA;
if(g_playing)
{
// if we have highlighting enabled, we need to redraw the whole grid
// so we can have the new colors in the matching colors.
// this should only be done when we are playing, because plain_board
// is actually the one being solved and thus displayed.
// this is true for all movement keys.
fill_grid(user_board, plain_board, x, y);
}

}
if(g_playing)
{
// if we have highlighting enabled, we need to redraw the whole grid
// so we can have the new colors in the matching colors.
// this should only be done when we are playing, because plain_board
// is actually the one being solved and thus displayed.
// this is true for all movement keys.
fill_grid(user_board, plain_board, x, y);
}
break;
case 'l':
case KEY_RIGHT:
if(x<34)
if ((x-GRID_NUMBER_START_X) / GRID_LINE_DELTA >= 8) {
x = GRID_NUMBER_START_X;
}
else if(x<34)
{
x += GRID_LINE_DELTA;
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
}
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
break;
case 'k':
case KEY_UP:
if(y>2)
if (y-GRID_NUMBER_START_Y <= 0) {
y = GRID_NUMBER_START_Y + GRID_COL_DELTA*8;
}
else if(y>2)
{
y -= GRID_COL_DELTA;
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
}
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
break;
case 'j':
case KEY_DOWN:
if(y<17)
if ((y-GRID_NUMBER_START_Y) / GRID_COL_DELTA >= 8) {
y = GRID_NUMBER_START_Y;
}
else if(y<17)
{
y += GRID_COL_DELTA;
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
}
if(g_playing)
{
fill_grid(user_board, plain_board, x, y);
}
break;
case 'Q':
Expand Down

0 comments on commit 44a55b9

Please sign in to comment.