--- /dev/null
+#include "board_renderer.h"
+#include "point.h"
+
+static Board *b = NULL;
+static WINDOW *win = NULL;
+static Point2i winPos;
+static Point2i winSize;
+
+void boardRenderer_init()
+{
+ Point2i termsize;
+
+ winPos = point2i(0,0);
+ getmaxyx(stdscr, termsize.y, termsize.x);
+ winSize = termsize;
+ winSize.y -= 2;
+
+ win = newwin(winSize.y, winSize.x, winPos.y, winPos.x);
+}
+
+void boardRenderer_render()
+{
+ wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
+ wrefresh(win);
+}
+
+void boardRenderer_set_board(Board *board)
+{
+ b = board;
+}
+
+void boardRenderer_cleanup()
+{
+ // clearing the border
+ wborder(win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
+ b = NULL;
+ delwin(win);
+}
--- /dev/null
+#ifndef BOARD_RENDERER_H
+#define BOARD_RENDERER_H
+#include <ncurses.h>
+#include "board.h"
+
+void boardRenderer_init();
+void boardRenderer_render();
+void boardRenderer_cleanup();
+void boardRenderer_set_board(Board *board);
+
+#endif//BOARD_RENDERER_H
#include <SDL2/SDL.h>
#include "board.h"
#include "point.h"
+#include "board_renderer.h"
#include <ncurses.h>
static Board* board = NULL;
}
initscr();
+ boardRenderer_init();
+ curs_set(false);
return true;
}
return -1;
}
- Uint32 itime = SDL_GetTicks();
- Uint32 ctime = 0;
- Point2i loc;
- Point2i bsize = board_get_size(board);
- Uint32 cclock = 0;
- Uint32 pclock = SDL_GetTicks();
- Point2i rpos = point2i(10,10); // where to draw the arr
-
- char *reprs = malloc(bsize.x * bsize.y * sizeof(char));
- char *elevs = malloc(bsize.x * bsize.y * sizeof(char));
- char *sel = NULL;
-
- for(int y = 0; y < bsize.y; ++y){
- for(int x = 0; x < bsize.x; ++x){
- elevs[x + (bsize.x * y)] =
- board_elevation_at(board, point2i(x, y)) + '0';
- reprs[x + (bsize.x * y)] =
- tile_repr(board_terrain_at(board, point2i(x, y)));
- }
- }
-
- draw_borders();
-
- // 'game' loop
- while(ctime < itime + 5000){
- ctime = SDL_GetTicks();
- cclock = SDL_GetTicks();
-
- // Switching the selection if needed
- if(cclock > pclock + 500 || pclock == 0){
- sel = (sel == reprs) ? elevs : reprs;
- pclock = cclock;
-
- for(int y = 0; y < bsize.y; ++y){
- for(int x = 0; x < bsize.x; ++x){
- mvaddch(y + rpos.y, x + rpos.x , sel[x + bsize.x * y]);
- }
- }
- refresh();
- }
- }
-
+ boardRenderer_render();
+ getchar();
SDL_Quit();
+ boardRenderer_cleanup();
endwin();
return 0;