Is anybody there who can help me please? I don't know what i have to change. I want to create a 2D grid and some other things.
Here's the most important part of my code.
#include <ncurses.h>
bool cells;
const MAX_GRID_SIZE;
//_________________________________________________
void initializeGame() {
initscr();
cbreak();
noecho();
curs_set(false);
nodelay(stdscr, true);
keypad(stdscr, true);
mousemask(ALL_MOUSE_EVENTS, NULL);
// Cells (0 = false, 1 = true).
MAX_GRID_SIZE = 500
cells[MAX_GRID_SIZE][MAX_GRID_SIZE] = { 0 };
}
//_________________________________________________
void showState() {
while (true) {
MEVENT event;
int key = getch();
if (key == KEY_MOUSE) {
if (getmouse(&event) == OK && (event.bstate & BUTTON1_CLICKED)) {
int x = event.x;
int y = event.y;
mvprintw(0, 0, "Mouse clicked at %d, %d\n", x, y);
cells[x][y] = !cells[x][y];
if (cells[x][y] == true) { attron(A_REVERSE); }
mvprintw(y, x, " ");
attroff(A_REVERSE);
refresh();
}
}
}
// Clean up.
endwin();
}
If cells
is meant to be a 2D array then declare it as such:
const size_t MAX_GRID_SIZE = 500;
bool cells[MAX_GRID_SIZE][MAX_GRID_SIZE] = { 0 };