aboutsummaryrefslogtreecommitdiffstats
path: root/highscore.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-03-26 07:04:01 +0000
committerH. Peter Anvin <hpa@zytor.com>2003-03-26 07:04:01 +0000
commit503aa676efd5f0e5216b84eec647e348ceb0b5c1 (patch)
tree45eae66dc836807f3936dfa0e01fcd6c7912344e /highscore.c
parent9bd970a1d7bc60d47e576b40857fa93a4690a83a (diff)
downloadgrv-503aa676efd5f0e5216b84eec647e348ceb0b5c1.tar.gz
grv-503aa676efd5f0e5216b84eec647e348ceb0b5c1.tar.xz
grv-503aa676efd5f0e5216b84eec647e348ceb0b5c1.zip
Getting close... the only thing missing now as far as I know is the
per-level highscore stuff (and if we want to add to the character set)
Diffstat (limited to 'highscore.c')
-rw-r--r--highscore.c191
1 files changed, 188 insertions, 3 deletions
diff --git a/highscore.c b/highscore.c
index 8b8dc4a..96b102c 100644
--- a/highscore.c
+++ b/highscore.c
@@ -14,10 +14,12 @@
#include "network.h"
static const char score_server[] = "grvscore.zytor.com";
-static int score_port = 22392;
+static int score_dl_port = 22392;
+static int score_ul_port = 22393;
static const char score_file[] = "grvscore.dat";
+
void highscore_download(void)
{
FILE *f;
@@ -29,13 +31,14 @@ void highscore_download(void)
}
if ( !opt.nonet ) {
- if ( (f = fopen_network(score_server, score_port, 0)) ) {
+ if ( (f = fopen_network(score_server, score_dl_port, 0)) ) {
highscore_parse(f);
fclose_network(f);
}
}
}
+
void highscore_upload(void)
{
FILE *f;
@@ -47,10 +50,192 @@ void highscore_upload(void)
}
if ( !opt.nonet ) {
- if ( (f = fopen_network(score_server, score_port, 1)) ) {
+ if ( (f = fopen_network(score_server, score_ul_port, 1)) ) {
highscore_write(f);
fclose_network(f);
}
}
}
+/*
+ * Allow the user to enter the name for the high score
+ */
+static void enter_name(int rank, char *player)
+{
+ static const unsigned char *symbols[3] = {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\x8f\x8e\x99""0123456789?",
+ "\x01\x02\x0e\x0f\x10\x11\x18\x19._-/:;+$%&^!*@=,'`~<>()\"\x80\x90\x92\x9a",
+ "\x13 SPACE DELETE ENTER "
+ };
+ int x, y, x1, y1;
+ int ly, ry, vy;
+ SDL_KeyboardEvent *ke;
+ int len = 0;
+ char sbuf[2];
+ char *s;
+
+ sbuf[1] = '\0';
+
+ SDL_EnableKeyRepeat(250, 33);
+
+ color(0,gp.c);
+ lprint(15,11,"ENTER YOUR INITIALS!");
+
+ color(0,gp.c2);
+ lprint(17,1,symbols[0]);
+ lprint(18,1,symbols[1]);
+ lprint(19,1,symbols[2]);
+
+ x = 0;
+ y = 0;
+ while ( 1 ) {
+ if ( x == 2 && y >= 12 ) {
+ if ( y >= 12 && y <= 20 ) {
+ y = 12; ly = 11; vy = 16; ry = 21;
+ s = " SPACE ";
+ sbuf[0] = ' ';
+ } else if ( y >= 21 && y <= 30 ) {
+ y = 21; ly = 12; vy = 25; ry = 31;
+ s = " DELETE ";
+ } else {
+ y = 31; ly = 21; vy = 35; ry = 31;
+ s = " ENTER ";
+ }
+ } else {
+ ly = max(0,y-1); vy = y; ry = min(39,y+1);
+ sbuf[0] = symbols[x][y];
+ s = sbuf;
+ }
+
+ color(15,gp.c2);
+ lprint(x+17,y+1,s);
+
+ x1 = x; y1 = y;
+
+ do {
+ ke = get_key();
+
+ if ( ke->keysym.sym == kbd_keys[0] ) {
+ x = max(0,x-1);
+ if ( x != x1 ) y = vy;
+ } else if ( ke->keysym.sym == kbd_keys[1] ) {
+ y = ly;
+ } else if ( ke->keysym.sym == kbd_keys[2] ) {
+ y = ry;
+ } else if ( ke->keysym.sym == kbd_keys[3] ) {
+ x = min(2,x+1);
+ if ( x != x1 ) y = vy;
+ } else if ( ke->keysym.sym == SDLK_RETURN ) {
+ if ( x == 2 && y == 21 ) {
+ if ( len > 0 ) {
+ len--;
+ color(0,gp.c2);
+ lprint(rank+3,len+23,".");
+ }
+ } else if ( x == 2 && y == 31 ) {
+ if ( len == 9 ) {
+ player[len] = '\0';
+ color(0,gp.c2);
+ lprint(rank+3,23,player);
+ return;
+ }
+ } else {
+ if ( len < 9 ) {
+ player[len] = sbuf[0];
+ color(15,gp.c2);
+ lprint(rank+3,len+23,sbuf);
+ len++;
+ }
+ }
+ }
+ } while ( x == x1 && y == y1 );
+
+ color(0,gp.c2);
+ lprint(x1+17,y1+1,s);
+ }
+}
+
+
+/*
+ * Display highscore screen; optionally show the user rank
+ * and (if <= 10) let the user enter name
+ */
+
+void highscore_show(int myrank, int upload)
+{
+ int i, x, y;
+
+ levelscreen();
+
+ color(0,gp.c);
+ lprint(1,15,"THE TOP TEN");
+
+ for ( i = 0 ; i < 10 ; i++ ) {
+ lprintf(i+4,4,"%2d %-13lld %-9.9s (%2d)",
+ i+1, bests.total[i].score,
+ bests.total[i].player,
+ bests.total[i].endlvl+1);
+
+ if ( i+1 == myrank ) {
+ color(0,gp.c2);
+ lprint(i+4,23,".........");
+ color(0,gp.c);
+ }
+ }
+
+ if ( myrank > 0 && myrank <= 10 )
+ enter_name(myrank, bests.total[myrank-1].player);
+
+ if ( upload ) {
+ /* This can't be done until we have let the user enter name,
+ and this is as good of a place as any, especially since
+ there is no blink on the screen right now... */
+ highscore_upload();
+ }
+
+ color(0,gp.c);
+ lprint(21,8,"Please press any key . . .");
+ get_key();
+
+ initscreen(80);
+
+ x = 1; y = 1;
+ for ( i = 10 ; i < 100 ; i++ ) {
+ if ( i+1 == myrank )
+ color(16,gp.c2);
+ else
+ color(0,gp.c);
+
+ lprintf(x,y, " %3d %-13lld ", i+1,
+ bests.total[i].score);
+
+ x++;
+ if ( x > 23 ) {
+ x = 1;
+ y += 20;
+ }
+ }
+
+ color(0,gp.c);
+ lprintf(25,28,"Please press any key . . .");
+ get_key();
+}
+
+/*
+ * Call at end of game to show and possibly enter highscore
+ * Note: always upload even if this wasn't a highscore -- we might have
+ * entries in our database from old games
+ */
+void highscore_endgame(void)
+{
+ int myrank;
+
+ highscore_download();
+
+ if ( gp.Cheat )
+ myrank = 0;
+ else
+ myrank = highscore_add_total(gp.gameid, gp.Sc, gp.MLev, NULL);
+
+ highscore_show(myrank, 1);
+}