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