Added easy extension of custom merge results. Example fib merge rules added. Code altered to make use of this new style
This commit is contained in:
+10
-25
@@ -3,11 +3,6 @@
|
||||
#include <unistd.h>
|
||||
#include "gfx.h"
|
||||
|
||||
#define GFX_EXTRA_UP case KEY_UP:
|
||||
#define GFX_EXTRA_DOWN case KEY_DOWN:
|
||||
#define GFX_EXTRA_RIGHT case KEY_RIGHT:
|
||||
#define GFX_EXTRA_LEFT case KEY_LEFT:
|
||||
|
||||
#define NUMBER_OF_COLORS 7
|
||||
|
||||
#define iterate(n, expression)\
|
||||
@@ -38,28 +33,18 @@ struct gfx_state* gfx_init(struct gamestate *g)
|
||||
if (g->opts->enable_color && has_colors()) {
|
||||
start_color();
|
||||
|
||||
int x = 0;
|
||||
init_pair(x++, 1, 0);
|
||||
init_pair(x++, 2, 0);
|
||||
init_pair(x++, 3, 0);
|
||||
init_pair(x++, 4, 0);
|
||||
init_pair(x++, 5, 0);
|
||||
init_pair(x++, 6, 0);
|
||||
init_pair(x++, 7, 0);
|
||||
char dummy[x == NUMBER_OF_COLORS ? 1 : -1];
|
||||
init_pair(0, 1, 0);
|
||||
init_pair(1, 2, 0);
|
||||
init_pair(2, 3, 0);
|
||||
init_pair(3, 4, 0);
|
||||
init_pair(4, 5, 0);
|
||||
init_pair(5, 6, 0);
|
||||
init_pair(6, 7, 0);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static int int_log2(int n)
|
||||
{
|
||||
int k = 0;
|
||||
while (n)
|
||||
++k, n /= 2;
|
||||
return k;
|
||||
}
|
||||
|
||||
void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||
{
|
||||
if (g->score_last)
|
||||
@@ -79,9 +64,9 @@ void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||
|
||||
for (x = 0; x < g->opts->grid_width; ++x) {
|
||||
if (g->grid[x][y]) {
|
||||
wattron(s->window, COLOR_PAIR(int_log2(g->grid[x][y]) % NUMBER_OF_COLORS));
|
||||
mvwprintw(s->window, ypos, xpos, "%*d", g->print_width, g->grid[x][y]);
|
||||
wattroff(s->window, COLOR_PAIR(int_log2(g->grid[x][y]) % NUMBER_OF_COLORS));
|
||||
wattron(s->window, COLOR_PAIR(g->grid[x][y] % NUMBER_OF_COLORS));
|
||||
mvwprintw(s->window, ypos, xpos, "%*ld", g->print_width, merge_value(g->grid[x][y]));
|
||||
wattroff(s->window, COLOR_PAIR(g->grid[x][y] % NUMBER_OF_COLORS));
|
||||
mvwprintw(s->window, ypos, xpos + g->print_width, " |");
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user