aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-03-31 17:01:26 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2020-03-31 17:01:26 -0500
commitca1dd8dfa3fbb0ca8f947b003b9e52bc2a686968 (patch)
treedb4ec86b631982795845a57cd9bb6fbbf09c3ace
parent4e1571bda9c6a85db4bd7a43f3044d855b091ec3 (diff)
downloadgemworm-ca1dd8dfa3fbb0ca8f947b003b9e52bc2a686968.zip
gemworm-ca1dd8dfa3fbb0ca8f947b003b9e52bc2a686968.tar.gz
Hall of fame now shows scores too.
-rw-r--r--scores.c13
-rw-r--r--scores.h3
-rw-r--r--worm.c19
3 files changed, 30 insertions, 5 deletions
diff --git a/scores.c b/scores.c
index 117f2da..f840692 100644
--- a/scores.c
+++ b/scores.c
@@ -28,7 +28,7 @@
#define SCOREFILE "worm.hi"
struct score {
- char initials[3];
+ char initials[4];
int score;
};
@@ -93,11 +93,12 @@ char scorebuf[8];
fgets(scorebuf, 8, fp);
scores[i].score = atoi(scorebuf);
}
+ scores[i].initials[3] = '\0';
fclose(fp);
} else {
for(i=0;i<10;i++) {
- memcpy(scores[i].initials, defaults[9-i], 3);
- scores[i].score = i == 0 ? 10 : (i * 100 + 100);
+ memcpy(scores[i].initials, defaults[i], 4);
+ scores[9-i].score = i == 0 ? 10 : (i * 500 + 100);
}
}
free(filename);
@@ -120,4 +121,8 @@ int i;
free(filename);
}
-
+char *get_score_at(int pos, int *score)
+{
+ *score = scores[pos].score;
+ return scores[pos].initials;
+}
diff --git a/scores.h b/scores.h
index 64540b7..05f53f0 100644
--- a/scores.h
+++ b/scores.h
@@ -1,5 +1,8 @@
#ifndef SCORES_HEADERS
#define SCORES_HEADERS
+void load_scores(const char *fullpath);
+void save_scores(const char *fullpath);
+char *get_score_at(int pos, int *score);
#endif /* SCORES_HEADERS */
diff --git a/worm.c b/worm.c
index 99a356b..dd1af07 100644
--- a/worm.c
+++ b/worm.c
@@ -48,6 +48,7 @@
#include "util.h"
#include "field.h"
#include "player.h"
+#include "scores.h"
/* Sometimes you may need to compile in some missing global
* arrays used within the gem libraries
@@ -109,6 +110,10 @@ void hndl_scores()
{
GRECT box,origin;
int i;
+const char *initials;
+int score;
+static char entry[10][18];
+char numtext[10];
/* ob_xywh(app_menu, MDESK, &origin); */
@@ -116,7 +121,16 @@ int i;
objc_draw(scores_box,0,2,box.g_x, box.g_y, box.g_w, box.g_h);
for(i=0;i<10;i++) {
- set_resource_string(scores_box, score_positions[i], "Jeff");
+ initials = get_score_at(i, &score);
+ strcpy(entry[i], initials);
+
+ /* Unsafe, but what the hell... AHCC doesn't have snprintf */
+ sprintf(numtext, "%d", score);
+
+ while(strlen(entry[i]) < 17 - strlen(numtext)) strcat(entry[i], ".");
+ strcat(entry[i], numtext);
+
+ set_resource_string(scores_box, score_positions[i], entry[i]);
}
form_do(scores_box,0);
@@ -436,6 +450,9 @@ EVMULT_OUT evout;
player = init_player();
field_init();
food_init();
+
+ /* High scores */
+ load_scores(argv[0]);
#ifdef DEBUG
printf("Game init complete\n");