make deck construction more robust
This commit is contained in:
+10
-11
@@ -35,12 +35,8 @@ Potion level: x - 21
|
|||||||
|
|
||||||
/* Game stats */
|
/* Game stats */
|
||||||
|
|
||||||
static char deck[] = {
|
/* main deck and room */
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, /* monster pack 1 (clubs) */
|
static char deck[44], room[] = {0, 0, 0, 0};
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, /* monster pack 2 (spades) */
|
|
||||||
14, 15, 16, 17, 18, 19, 20, 21, 22, /* weapon pack (diamonds) */
|
|
||||||
23, 24, 25, 26, 27, 28, 29, 30, 31 /* potion pack (hearts) */
|
|
||||||
}, room[] = {0, 0, 0, 0};
|
|
||||||
|
|
||||||
static short deck_idx = 0, hp = 20,
|
static short deck_idx = 0, hp = 20,
|
||||||
weapon = 0, durability = 0, can_run = 1,
|
weapon = 0, durability = 0, can_run = 1,
|
||||||
@@ -186,6 +182,9 @@ int game() {
|
|||||||
int last_room = 0, last_room_clr = 0; /* last room markers */
|
int last_room = 0, last_room_clr = 0; /* last room markers */
|
||||||
char ch;
|
char ch;
|
||||||
deck_idx = 0; /* reset the deck index */
|
deck_idx = 0; /* reset the deck index */
|
||||||
|
/* Prefill the deck */
|
||||||
|
for(i=0;i<13;i++) deck[i] = deck[i+13] = i+1;
|
||||||
|
for(i=26;i<44;i++) deck[i] = i - 12;
|
||||||
/* Shuffle the deck */
|
/* Shuffle the deck */
|
||||||
shuffle(deck, sizeof(deck));
|
shuffle(deck, sizeof(deck));
|
||||||
/* prepare all other parameters */
|
/* prepare all other parameters */
|
||||||
@@ -245,16 +244,16 @@ int game() {
|
|||||||
|
|
||||||
/* 1. Collect all valid remaining cards from deck */
|
/* 1. Collect all valid remaining cards from deck */
|
||||||
for(i=0; i<sizeof(deck); i++) {
|
for(i=0; i<sizeof(deck); i++) {
|
||||||
if(deck[i] != 0) temp_deck[t_idx++] = deck[i];
|
if(deck[i] != 0) temp_deck[t_idx++] = deck[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2. Shuffle room cards and append to the end */
|
/* 2. Shuffle room cards and append to the end */
|
||||||
shuffle(room, sizeof(room));
|
shuffle(room, sizeof(room));
|
||||||
for(i=0; i<sizeof(room); i++) {
|
for(i=0; i<sizeof(room); i++) {
|
||||||
if(room[i] != 0) {
|
if(room[i] != 0) {
|
||||||
temp_deck[t_idx++] = room[i];
|
temp_deck[t_idx++] = room[i];
|
||||||
room[i] = 0; /* Clear room */
|
room[i] = 0; /* Clear room */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3. Rebuild deck */
|
/* 3. Rebuild deck */
|
||||||
|
|||||||
Reference in New Issue
Block a user