aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/main.c b/main.c
index 06c4e18..b7044a6 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include <time.h>
@@ -46,26 +47,39 @@ void init_ncurses(void) {
initialize_colors();
}
-int main(void) {
+int main(int argc, char **argv) {
+ Position start_pos, end_pos;
+ size_t width, height;
+ Map map;
+
+ size_t mwidth = 20; /* Maze width */
+ size_t mheight = 10; /* Maze height */
+
+ char is_maze = 0;
+ if (argc == 1 || !strcmp(argv[1], "-m")) {
+ is_maze = 1;
+ if (argc == 4) { /* maze size as argv[2] and [3] */
+ mwidth = atoi(argv[2]);
+ mheight = atoi(argv[3]);
+ }
+ map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
+ start_pos.x = 0;
+ start_pos.y = 0;
+ height = mheight * 2 - 1;
+ width = mwidth * 2 - 1;
+ end_pos.x = width - 1;
+ end_pos.y = height - 1;
+ } else {
+ map = file_plaintext_map(argv[1], &width, &height, &start_pos, &end_pos);
+ }
signal(SIGINT, sigint_handler);
init_ncurses();
- size_t mwidth = 20; /* Maze width */
- size_t mheight = 10; /* Maze height */
- Map map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
- Position start_pos = {0, 0};
- Position end_pos = {mwidth*2-2, mheight*2-2};
- size_t height = mheight * 2 - 1;
- size_t width = mwidth * 2 - 1;
int offset_x = 0, offset_y = 0;
- //size_t width, height;
- //Position start_pos, end_pos;
- //Map map = file_plaintext_map("maps/test", &width, &height, &start_pos, &end_pos);
- //print_map_out(map, width, height);
- //draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL);
-
+ draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL, NULL);
+
char visited[height][width];
Path path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos, visited);
@@ -78,9 +92,11 @@ int main(void) {
case 'j': offset_y += 1; break;
case 'k': offset_y -= 1; break;
case 'n':
- //FIXME: free it all before generating a new one
- map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
- path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos, visited);
+ if (is_maze) {
+ //FIXME: free it all before generating a new one
+ map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
+ path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos, visited);
+ }
break;
case 'q': endwin(); return 0;
}