From 73f185e1c560a448ad4df99f79d678fba5665614 Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 18 May 2018 01:27:56 +0200 Subject: [PATCH] different food values --- README.md | 3 +++ schemes.h | 6 ++++-- viiper.c | 18 ++++++++++++------ viiper.h | 13 +++++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9745007..4ef7b18 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # VIIper - a Snake Clone for Unicode-compatible Terminals +TODO: find a better name + ## Dependencies - A VTE based terminal (like GNOME Terminal and a whole bunch of others) @@ -20,6 +22,7 @@ r to restart, p to pause, q to quit. - timer, score, increasing speed - special items: slower snake, shorter snake, etc. - input buffer (so fast 180° turns get executed) + - wall-wrap-around mode? ## Notes diff --git a/schemes.h b/schemes.h index f599031..1e1006a 100644 --- a/schemes.h +++ b/schemes.h @@ -16,7 +16,7 @@ struct scheme { char* snake[5][5]; /* [predecessor][successor] */ - char* item[NUM_ITEMS]; + char* item[NUM_FOODS]; }; struct scheme unic0de = { @@ -62,7 +62,9 @@ struct scheme unic0de = { }, .item = { - [FOOD_10] = "🍎" + [FOOD_5] = "🍐", + [FOOD_10] = "🍎", + [FOOD_20] = "🥑", }, }; diff --git a/viiper.c b/viiper.c index ec4cea0..835518e 100644 --- a/viiper.c +++ b/viiper.c @@ -96,7 +96,7 @@ int viiper(void) { timer_setup(1); - spawn_item(FOOD_10); + spawn_item(FOOD, rand() % NUM_FOODS); //TODO: shape distribution, so bigger values get selected less for(;;) { switch (getctrlseq()) { @@ -128,7 +128,7 @@ void snake_advance (void) { for (struct item* i = g.i; i; i = i->next) { if (i->r == new_row && i->c == new_col) { consume_item (i); - spawn_item(FOOD_10); + spawn_item(FOOD, rand() % NUM_FOODS); } } @@ -151,7 +151,7 @@ void snake_advance (void) { g.s = new_head; } -void spawn_item (int type) { +void spawn_item (int type, int value) { int row, col; try_again: row = rand() % g.h; @@ -166,6 +166,7 @@ try_again: new_item->r = row; new_item->c = col; new_item->t = type; + new_item->v = value; new_item->s = time(0); if (g.i) g.i->prev = new_item; new_item->next = g.i; @@ -178,8 +179,12 @@ void consume_item (struct item* i) { struct item* successor = i->next; switch (i->t) { - case FOOD_10: - g.p+=10; + case FOOD: + switch (i->v) { + case FOOD_5: g.p += 5; break; + case FOOD_10: g.p += 10; break; + case FOOD_20: g.p += 20; break; + } snake_append(g.s, 0,0); /* position doesn't matter, as item */ break; /* will be reused as the head before it is drawn */ case BONUS: @@ -238,7 +243,8 @@ void show_playfield (void) { /* print item queue */ for (struct item* i = g.i; i; i = i->next) { move_ph (i->r+LINE_OFFSET, i->c*CW+COL_OFFSET); - print (op.scheme->item[i->t]); + if (i->t == FOOD) print (op.scheme->item[i->v]); + else if (i->t==BONUS) /* TODO: print bonus */; } } diff --git a/viiper.h b/viiper.h index cd00a47..23d68e7 100644 --- a/viiper.h +++ b/viiper.h @@ -38,17 +38,22 @@ enum direction { }; enum item_type { NO_ITEM, + FOOD, + BONUS, +}; +enum food_value { FOOD_5, FOOD_10, FOOD_20, - BONUS, - - NUM_ITEMS, + NUM_FOODS, +}; +enum bonus_value { + NUM_BONI, }; int viiper(void); void snake_advance (void); -void spawn_item (int type); +void spawn_item (int type, int value); void consume_item (struct item* i); void show_playfield (void); void snake_append (struct snake* s, int row, int col); -- 2.39.3