Doesn't work segfaults.
This commit is contained in:
@@ -1,15 +1,39 @@
|
||||
#include <ncurses.h>
|
||||
#include "game.h"
|
||||
#include "grid.h"
|
||||
#include "vect.h"
|
||||
|
||||
static Grid grid;
|
||||
static Grid* grid = 0;
|
||||
|
||||
static bool running = true;
|
||||
static bool do_step = true;
|
||||
static Vect2i cursor = {0, 0};
|
||||
static Vect2i cursor;
|
||||
|
||||
void initGame()
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
// stdscr is screen created by initscr()
|
||||
getmaxyx(stdscr, height, width);
|
||||
|
||||
initGrid(grid, height, width);
|
||||
randomizeGrid(grid);
|
||||
cursor.x = width/2; cursor.y = height/2;
|
||||
}
|
||||
|
||||
static void step() { do_step ^= 1; }
|
||||
|
||||
void updateGame()
|
||||
{
|
||||
if (!grid) return;
|
||||
if (do_step) updateGrid(grid);
|
||||
}
|
||||
|
||||
void drawGame()
|
||||
{
|
||||
if (!grid) return;
|
||||
drawGrid(grid);
|
||||
refresh();
|
||||
}
|
||||
|
||||
bool isRunning() { return running; }
|
||||
@@ -17,27 +41,39 @@ bool isRunning() { return running; }
|
||||
void handleInput(char ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case 'q':
|
||||
running = false;
|
||||
break;
|
||||
case ' ':
|
||||
do_step ^= 1;
|
||||
break;
|
||||
case 'h':
|
||||
moveVect2i(&cursor, -1, 0);
|
||||
break;
|
||||
case 'j':
|
||||
moveVect2i(&cursor, 0, 1);
|
||||
break;
|
||||
case 'k':
|
||||
moveVect2i(&cursor, 0, -1);
|
||||
break;
|
||||
case 'l':
|
||||
moveVect2i(&cursor, 1, 0);
|
||||
break;
|
||||
case 'q':
|
||||
running = false;
|
||||
break;
|
||||
case ' ':
|
||||
do_step ^= 1;
|
||||
break;
|
||||
case 'h':
|
||||
moveVect2i(&cursor, -1, 0);
|
||||
break;
|
||||
case 'j':
|
||||
moveVect2i(&cursor, 0, 1);
|
||||
break;
|
||||
case 'k':
|
||||
moveVect2i(&cursor, 0, -1);
|
||||
break;
|
||||
case 'l':
|
||||
moveVect2i(&cursor, 1, 0);
|
||||
break;
|
||||
case 's':
|
||||
step();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void showLastPressed(char ch)
|
||||
{
|
||||
static char lastc = ' ';
|
||||
if (ch != -1) lastc = ch;
|
||||
attron(COLOR_PAIR(2));
|
||||
mvprintw(0, 0, "Last Pressed: %c", lastc);
|
||||
attroff(COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
void showCurPos()
|
||||
{
|
||||
attron(COLOR_PAIR(2));
|
||||
|
||||
Reference in New Issue
Block a user