aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 5734db89c554cc88acc07535b98a6ee1c3f73bae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "map.h"
#include "structs.h"
#include "config.h"

/* So, TODO for now:
   - Implement Dijkstra and greedy-best-first search algorithms
   - Implement the A* algorithm
   - Implement adding maps from files (with rle, preferably)
   - Implement controls (to change maps, move start/goal, etc.) */

void sigint_handler(int sig) {
    (void)sig; /* We know it's a SIGINT */
    endwin();
    printf("Received SIGINT\n");
    exit(1);
}

void initialize_colors(void) {
    start_color();
    use_default_colors();
    init_pair(EMPTY_COLOR, COLOR_BLACK, -1);
    init_pair(GOAL_COLOR, COLOR_RED, -1);
    init_pair(WALL_COLOR, COLOR_WHITE, COLOR_WHITE); /* Using white as bg makes
                                                        them seem solid */
    init_pair(START_COLOR, COLOR_RED, -1);
}

int main(void) {
    signal(SIGINT, sigint_handler);

    initscr();     /* Initialize the ncurses screen */
    cbreak();      /* Process input one char at a time */
    curs_set(0);   /* Hide the cursor */
    noecho();      /* Don't echo characters */
    initialize_colors();

    /* FIXME: shitty. sometimes leaves enough space on the right for a bigger map */
    size_t height = LINES/2 - DRAW_MAP_OFFSET_Y,
           width = COLS/4 - 1;
    Map map = rbt_maze_map(width, height, (unsigned int) time(NULL));
    Position fake_start_position_to_pass_into_draw_map = {0, 0};
    Position fake_goal_position_to_pass_into_draw_map = {width*2-2, height*2-2};
    draw_map(map, width*2-1, height*2-1, fake_start_position_to_pass_into_draw_map, fake_goal_position_to_pass_into_draw_map);
    getch();

    endwin();
    return 0;
}