From ae59eea6c0b8fe2a71896120f196fc200bec56fb Mon Sep 17 00:00:00 2001 From: Nathan Vance Date: Tue, 17 Feb 2015 10:35:41 -0500 Subject: Now separates out cards for a deck and shuffles! --- cards.c | 8 ++++---- decks.c | 24 +++++++++++++++++++++++- main.c | 11 +++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cards.c b/cards.c index 47129c3..c696abf 100644 --- a/cards.c +++ b/cards.c @@ -10,8 +10,8 @@ char* get_chararray(int size); int* get_intarray(int size); -//era, card#, resource cost / resource production / coupons / couponed by / card name -static int cards[3][CARDSPERERA][200]; +//era, card#, resource cost / resource production / coupons / couponed by / card name / description +static int cards[3][CARDSPERERA][300]; void cards_setcost(int era, int card, int res, int num) { @@ -84,7 +84,7 @@ void cards_updatecoupons() int i, j, k; int* card; for(i = 0; i <= 1; i++) { - for(j = 0; j < CARDSPERERA; j++) { + for(j = 0; j < 27-4*i; j++) { for(k = STARTCOUPONS; k <= STARTCOUPONS+2; k += 2) { if(cards[i][j][k]) { card = cards[cards[i][j][k]][cards[i][j][k+1]]; @@ -124,7 +124,7 @@ void cards_setmessage(int era, int card, char *message) char* cards_specialmessage(int era, int card) { - char *ret = get_chararray(100); + char *ret = get_chararray(200); int i; for(i = 0; (ret[i] = cards[era][card][STARTDESCRIPTION+i]) != '\0'; i++); return ret; diff --git a/decks.c b/decks.c index 0a1f2c2..8f6e22a 100644 --- a/decks.c +++ b/decks.c @@ -24,9 +24,12 @@ void shuffle(int *deck, int n) int scratch[n]; int i = 0; int size = n; + int k; srand(time(NULL)); while(n) { - scratch[i++] = deck[rand()%n]; + k = rand()%n; + scratch[i++] = deck[k]; + for(; k < n-1; k++) deck[k] = deck[k+1]; n--; } for(i = 0; i < size; i++) deck[i] = scratch[i]; @@ -35,4 +38,23 @@ void shuffle(int *deck, int n) int* getdeck(int era, int numplayers) { int *ret = get_intarray(numplayers*7); + int guilds[10]; + int i, j; + switch(era) { + case 0: + for(i = 0; i < numplayers*7; i++) ret[i] = era1[i]; + break; + case 1: + for(i = 0; i < numplayers*7; i++) ret[i] = era2[i]; + break; + case 2: + for(i = 0; i < 10; i++) guilds[i] = i+18; + shuffle(guilds, 10); + for(i = 0; i < numplayers*6-1; i++) ret[i] = era3[i]; + for(j = 0; i < numplayers*7; i++, j++) ret[i] = guilds[j]; + break; + default: break; + } + shuffle(ret, numplayers*7); + return ret; } diff --git a/main.c b/main.c index 54c464e..1215890 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ void cards_init(); void io_printcard(int x, int y, int era, int card); void cardtour(); void io_clearscreen(); +int* getdeck(int era, int numplayers); void halt() { @@ -31,11 +32,17 @@ void cardtour() { int era, card; era = card = 0; + int deckpos = 0; + int numplayers = 4; + int *decks[3]; + decks[0] = getdeck(0, numplayers); + decks[1] = getdeck(1, numplayers); + decks[2] = getdeck(2, numplayers); while(1) { io_clearscreen(); - io_printcard(0, 0, era, card); + io_printcard(0, 0, era, decks[era][card]); switch(io_getkey()) { - case DOWN: if(card < CARDSPERERA-1) card++; + case DOWN: if(card < numplayers*7) card++; break; case UP: if(card > 0) card--; break; -- cgit