small scoring optimization
This commit is contained in:
+4
-10
@@ -163,7 +163,7 @@ void shuffle(char *array, size_t n) {
|
|||||||
|
|
||||||
/* Room item handling methods */
|
/* Room item handling methods */
|
||||||
|
|
||||||
void handle_monster(int val) {
|
int handle_monster(int val) {
|
||||||
int healthlost = val;
|
int healthlost = val;
|
||||||
printf("You fight a %d-level monster.\n", val);
|
printf("You fight a %d-level monster.\n", val);
|
||||||
if(weapon > 0 && val <= durability) {
|
if(weapon > 0 && val <= durability) {
|
||||||
@@ -184,6 +184,7 @@ void handle_monster(int val) {
|
|||||||
hp -= healthlost;
|
hp -= healthlost;
|
||||||
if(hp < 0) hp = 0;
|
if(hp < 0) hp = 0;
|
||||||
printf("You lost %d HP. New HP: %d.\n", healthlost, hp);
|
printf("You lost %d HP. New HP: %d.\n", healthlost, hp);
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_weapon(int val) {
|
void handle_weapon(int val) {
|
||||||
@@ -208,7 +209,7 @@ void handle_potion(int val) {
|
|||||||
/* Main gameplay */
|
/* Main gameplay */
|
||||||
int game() {
|
int game() {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int score = 0; /* score storage */
|
int score = -208; /* score storage */
|
||||||
int item, room_sum; /* true item value */
|
int item, room_sum; /* true item value */
|
||||||
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;
|
||||||
@@ -306,7 +307,7 @@ int game() {
|
|||||||
/* Note: We do NOT put the item back in deck. It is consumed. */
|
/* Note: We do NOT put the item back in deck. It is consumed. */
|
||||||
|
|
||||||
if(item < 14) { /* monster */
|
if(item < 14) { /* monster */
|
||||||
handle_monster(item + 1);
|
score += handle_monster(item + 1);
|
||||||
} else if(item < 23) { /* weapon */
|
} else if(item < 23) { /* weapon */
|
||||||
handle_weapon(item - 12);
|
handle_weapon(item - 12);
|
||||||
} else { /* potion */
|
} else { /* potion */
|
||||||
@@ -339,13 +340,6 @@ int game() {
|
|||||||
if(hp > 0) { /* win */
|
if(hp > 0) { /* win */
|
||||||
score = hp;
|
score = hp;
|
||||||
if(hp == 20) score += last_potion_val;
|
if(hp == 20) score += last_potion_val;
|
||||||
} else { /* fail */
|
|
||||||
for(i=0;i<sizeof(room);i++)
|
|
||||||
if(room[i] && room[i] < 14)
|
|
||||||
score -= (room[i] + 1);
|
|
||||||
for(i=0;i<sizeof(deck);i++)
|
|
||||||
if(deck[i] && deck[i] < 14)
|
|
||||||
score -= (deck[i] + 1);
|
|
||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-10
@@ -445,7 +445,7 @@ void shuffle(char *array, unsigned int n) {
|
|||||||
|
|
||||||
/* Room item handling methods */
|
/* Room item handling methods */
|
||||||
|
|
||||||
void handle_monster(int val) {
|
int handle_monster(int val) {
|
||||||
int healthlost = val;
|
int healthlost = val;
|
||||||
char monster_msg[(SCREEN_WIDTH-1)];
|
char monster_msg[(SCREEN_WIDTH-1)];
|
||||||
beep_enemy();
|
beep_enemy();
|
||||||
@@ -466,6 +466,7 @@ void handle_monster(int val) {
|
|||||||
hp -= healthlost;
|
hp -= healthlost;
|
||||||
if(hp < 0) hp = 0;
|
if(hp < 0) hp = 0;
|
||||||
snprintf(status_msg, sizeof(status_msg), "You lost %d HP. New HP: %d", healthlost, hp);
|
snprintf(status_msg, sizeof(status_msg), "You lost %d HP. New HP: %d", healthlost, hp);
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_weapon(int val) {
|
void handle_weapon(int val) {
|
||||||
@@ -493,7 +494,7 @@ void handle_potion(unsigned char val) {
|
|||||||
/* Main gameplay */
|
/* Main gameplay */
|
||||||
int game() {
|
int game() {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int score = 0; /* score storage */
|
int score = -208; /* score storage */
|
||||||
int item, room_sum; /* true item value */
|
int item, room_sum; /* true item value */
|
||||||
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;
|
||||||
@@ -592,7 +593,7 @@ int game() {
|
|||||||
/* Note: We do NOT put the item back in deck. It is consumed. */
|
/* Note: We do NOT put the item back in deck. It is consumed. */
|
||||||
|
|
||||||
if(item < 14) { /* monster */
|
if(item < 14) { /* monster */
|
||||||
handle_monster(item + 1);
|
score += handle_monster(item + 1);
|
||||||
} else if(item < 23) { /* weapon */
|
} else if(item < 23) { /* weapon */
|
||||||
handle_weapon(item - 12);
|
handle_weapon(item - 12);
|
||||||
} else { /* potion */
|
} else { /* potion */
|
||||||
@@ -625,13 +626,6 @@ int game() {
|
|||||||
if(hp > 0) { /* win */
|
if(hp > 0) { /* win */
|
||||||
score = hp;
|
score = hp;
|
||||||
if(hp == 20) score += last_potion_val;
|
if(hp == 20) score += last_potion_val;
|
||||||
} else { /* fail */
|
|
||||||
for(i=0;i<sizeof(room);i++)
|
|
||||||
if(room[i] && room[i] < 14)
|
|
||||||
score -= (room[i] + 1);
|
|
||||||
for(i=0;i<sizeof(deck);i++)
|
|
||||||
if(deck[i] && deck[i] < 14)
|
|
||||||
score -= (deck[i] + 1);
|
|
||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user