diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 2001-02-04 14:23:29 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 2001-02-04 14:23:29 +0000 |
commit | 0cefa5ef4bf99b94fd445ca80273f4cfe94ef9d6 (patch) | |
tree | af1924fef615e8db115214f823a33d0fcbf73f2e /games/tetris | |
parent | aedb1ae9a8b4169c2199cad5c58fb7179fd18c4d (diff) |
Long usernames. This really messes up the scoreboard printout, so change
it from two columns to one column with leaders printed every third score
to guide the eye across the vast whitespace that's left with the
traditional 8-char usernames.
Diffstat (limited to 'games/tetris')
-rw-r--r-- | games/tetris/input.c | 4 | ||||
-rw-r--r-- | games/tetris/scores.c | 103 | ||||
-rw-r--r-- | games/tetris/scores.h | 4 | ||||
-rw-r--r-- | games/tetris/tetris.c | 3 |
4 files changed, 48 insertions, 66 deletions
diff --git a/games/tetris/input.c b/games/tetris/input.c index 3ce2f21c5cd..d2cdc003b0b 100644 --- a/games/tetris/input.c +++ b/games/tetris/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.4 1999/03/22 07:38:24 pjanzen Exp $ */ +/* $OpenBSD: input.c,v 1.5 2001/02/04 14:23:27 pjanzen Exp $ */ /* $NetBSD: input.c,v 1.3 1996/02/06 22:47:33 jtc Exp $ */ /*- @@ -93,7 +93,7 @@ rwait(tvp) endtv = *tvp; s = &endtv; } else - s = 0; + s = NULL; again: i = 1; switch (select(1, (fd_set *)&i, (fd_set *)0, (fd_set *)0, s)) { diff --git a/games/tetris/scores.c b/games/tetris/scores.c index 48cdf7b3a4b..b46aa7b0ce2 100644 --- a/games/tetris/scores.c +++ b/games/tetris/scores.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scores.c,v 1.4 2000/01/21 05:33:19 pjanzen Exp $ */ +/* $OpenBSD: scores.c,v 1.5 2001/02/04 14:23:27 pjanzen Exp $ */ /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ /*- @@ -56,6 +56,7 @@ #include <time.h> #include <term.h> #include <unistd.h> +#include <sys/param.h> #include <sys/stat.h> #include <sys/types.h> @@ -222,9 +223,8 @@ savescore(level) static char * thisuser() { - register const char *p; - register struct passwd *pw; - register size_t l; + const char *p; + struct passwd *pw; static char u[sizeof(scores[0].hs_name)]; if (u[0]) @@ -237,11 +237,7 @@ thisuser() else p = " ???"; } - l = strlen(p); - if (l >= sizeof(u)) - l = sizeof(u) - 1; - memcpy(u, p, l); - u[l] = '\0'; + strlcpy(u, p, sizeof(u)); return (u); } @@ -366,7 +362,7 @@ showscores(level) if (!gotscores) getscores((FILE **)NULL); - (void)printf("\n\t\t\t Tetris High Scores\n"); + (void)printf("\n\t\t Tetris High Scores\n"); /* * If level == 0, the person has not played a game but just asked for @@ -393,7 +389,7 @@ showscores(level) * Page each screenful of scores. */ for (i = 0, sp = scores; i < nscores; sp += n) { - n = 40; + n = 20; if (i + n > nscores) n = nscores - i; printem(level, i + 1, sp, n, me); @@ -414,63 +410,48 @@ showscores(level) static void printem(level, offset, hs, n, me) int level, offset; - register struct highscore *hs; - register int n; + struct highscore *hs; + int n; const char *me; { - register struct highscore *sp; - int nrows, row, col, item, i, highlight; + struct highscore *sp; + int row, highlight, i; char buf[100]; -#define TITLE "Rank Score Name (points/level)" +#define TITLE "Rank Score Name (points/level)" +#define TITL2 "==========================================================" - /* - * This makes a nice two-column sort with headers, but it's a bit - * convoluted... - */ - printf("%s %s\n", TITLE, n > 1 ? TITLE : ""); + printf("%s\n%s\n", TITLE, TITL2); highlight = 0; - nrows = (n + 1) / 2; - for (row = 0; row < nrows; row++) { - for (col = 0; col < 2; col++) { - item = col * nrows + row; - if (item >= n) { - /* - * Can only occur on trailing columns. - */ - (void)putchar('\n'); - continue; - } - sp = &hs[item]; - (void)sprintf(buf, - "%3d%c %6d %-11s (%6d on %d)", - item + offset, sp->hs_time ? '*' : ' ', - sp->hs_score * sp->hs_level, - sp->hs_name, sp->hs_score, sp->hs_level); - /* - * Highlight if appropriate. This works because - * we only get one score per level. - */ - if (me != NULL && - sp->hs_level == level && - sp->hs_score == score && - strcmp(sp->hs_name, me) == 0) { - putpad(SOstr); - highlight = 1; - } - (void)printf("%s", buf); - if (highlight) { - putpad(SEstr); - highlight = 0; - } - - /* fill in spaces so column 1 lines up */ - if (col == 0) - for (i = 40 - strlen(buf); --i >= 0;) - (void)putchar(' '); - else /* col == 1 */ - (void)putchar('\n'); + for (row = 0; row < n; row++) { + sp = &hs[row]; + (void)snprintf(buf, 100, + "%3d%c %6d %-31s (%6d on %d)\n", + row + offset, sp->hs_time ? '*' : ' ', + sp->hs_score * sp->hs_level, + sp->hs_name, sp->hs_score, sp->hs_level); + /* Print leaders every three lines */ + if ((row + 1) % 3 == 0) { + for (i = 0; i < 100; i++) + if (buf[i] == ' ') + buf[i] = '_'; + } + /* + * Highlight if appropriate. This works because + * we only get one score per level. + */ + if (me != NULL && + sp->hs_level == level && + sp->hs_score == score && + strcmp(sp->hs_name, me) == 0) { + putpad(SOstr); + highlight = 1; + } + (void)printf("%s", buf); + if (highlight) { + putpad(SEstr); + highlight = 0; } } } diff --git a/games/tetris/scores.h b/games/tetris/scores.h index de4dc5c5fd8..500e8731b77 100644 --- a/games/tetris/scores.h +++ b/games/tetris/scores.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scores.h,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ +/* $OpenBSD: scores.h,v 1.3 2001/02/04 14:23:28 pjanzen Exp $ */ /* $NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd Exp $ */ /*- @@ -43,7 +43,7 @@ * Tetris scores. */ struct highscore { - char hs_name[20]; /* login name */ + char hs_name[MAXLOGNAME]; /* login name */ int hs_score; /* raw score */ int hs_level; /* play level */ time_t hs_time; /* time at game end */ diff --git a/games/tetris/tetris.c b/games/tetris/tetris.c index d36b03fcf8a..312dad9228e 100644 --- a/games/tetris/tetris.c +++ b/games/tetris/tetris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tetris.c,v 1.8 2000/01/03 23:22:45 pjanzen Exp $ */ +/* $OpenBSD: tetris.c,v 1.9 2001/02/04 14:23:28 pjanzen Exp $ */ /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ /*- @@ -49,6 +49,7 @@ static char copyright[] = * Tetris (or however it is spelled). */ +#include <sys/param.h> #include <sys/time.h> #include <sys/types.h> |