DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T s

⟦327f3e614⟧ TextFile

    Length: 5685 (0x1635)
    Types: TextFile
    Names: »score.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Xtetris/score.c« 

TextFile

#include "defs.h"

update_highscore_table()
{
    /* This version only allows 1 entry in the HIGH SCORE TABLE per user */
        int     i, j;
        long    when;
        extern char *ctime();
        extern long time();
        char    hostname[20];
        char    buf[BUFSIZ];

        /* re-read high-score table in case someone else on the network is
         * playing at the same time */
        read_high_scores();

        /* Check for previous best score */
        for (i = 0; (i < HIGH_TABLE_SIZE) && (strcmp(name, high_scores[i].name) != 0); i++);
        if (i < HIGH_TABLE_SIZE) {
                if (high_scores[i].score >= score)
                        return;         /* Same/worse score - no update */
                for (j = i; j > 0; j--) /* Remove previous best */
                        high_scores[j] = high_scores[j - 1];
        }
        /* Next line finds score greater than current one */
        for (i = 0; ((i < HIGH_TABLE_SIZE) && (score >= high_scores[i].score)); i++);
        i--;
        if (i >= 0) {
                for (j = 0; j < i; j++)
                        high_scores[j] = high_scores[j + 1];
                strcpy(high_scores[i].name, name);
                high_scores[i].score = score;
                high_scores[i].rows = rows;
                high_scores[i].level = rows / 10;
                if (gethostname(hostname, BUFSIZ) == -1)
                        strcpy(high_scores[i].hostname, "unknown-host");
                else
                        strcpy(high_scores[i].hostname, hostname);
                time(&when);
                strcpy(buf, ctime(&when));      /* ctime() adds a newline
                                                 * char */
                strip_eoln(buf);                /* so remove it */
                strcpy(high_scores[i].date, buf);
                write_high_scores();
        }
}


read_high_scores()
{
        FILE   *fp;
        int     i;
        char   *c, buf[BUFSIZ];

        for (i = 0; i < HIGH_TABLE_SIZE; i++) {
                strcpy(high_scores[i].name, " ");
                high_scores[i].score = 0;
                high_scores[i].rows = 0;
                high_scores[i].level = 0;
                strcpy(high_scores[i].hostname, " ");
                strcpy(high_scores[i].date, " ");
        }
        if ((fp = fopen(HIGH_SCORE_TABLE, "r")) == NULL) {
                fprintf(stderr, "tetris: No High score file\n");
                return;
        }
        for (i = 0; i < HIGH_TABLE_SIZE; i++) {
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                strcpy(high_scores[i].name, buf);
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                high_scores[i].score = atoi(buf);
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                high_scores[i].rows = atoi(buf);
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                high_scores[i].level = atoi(buf);
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                strcpy(high_scores[i].hostname, buf);
                fgets(buf, BUFSIZ, fp);
                strip_eoln(buf);
                strcpy(high_scores[i].date, buf);
        }
        fclose(fp);
}

strip_eoln(s)
        char   *s;
{
        char   *s1;

        while (*s != '\0') {
                if (*s == '\n') {       /* End of line char */
                        s1 = s;
                        do {
                                *s1 = *(s1 + 1);        /* Copy rest of string */
                                s1++;
                        } while (*s1 != '\0');
                } else
                        s++;
        }
}

write_high_scores()
{
        FILE   *fp;
        int     i;

        if ((fp = fopen(HIGH_SCORE_TABLE, "w")) == NULL) {
                fprintf(stderr, "tetris: Couldn't open high score file %s\n", HIGH_SCORE_TABLE);
                return;
        }
        for (i = 0; i < HIGH_TABLE_SIZE; i++)
                fprintf(fp, "%s\n%d\n%d\n%d\n%s\n%s\n",
                        high_scores[i].name,
                        high_scores[i].score,
                        high_scores[i].rows,
                        high_scores[i].level,
                        high_scores[i].hostname,
                        high_scores[i].date);
        fclose(fp);
}

void
print_high_scores()
{
        int     i,j;
        char    buf[BUFSIZ];

        /* re-read high-score table in case someone else on the network is
         * playing at the same time */
        read_high_scores();

        for (i = HIGH_TABLE_SIZE - 1; i >= 0; i--) {
                sprintf(buf, "%3d) %-15s %6d %5d %3d  %-10s  %s \n",
                        HIGH_TABLE_SIZE - i,
                        high_scores[i].name,
                        high_scores[i].score,
                        high_scores[i].rows,
                        high_scores[i].level,
                        high_scores[i].hostname,
                        high_scores[i].date);
                j=0;
                XtSetArg(args[j], XtNstring, buf); j++;
                XtSetValues(high_score_item[HIGH_TABLE_SIZE - i],args,j);
        }
	XtPopup(score_frame, XtGrabExclusive);
}

print_authors()
{
	printf("This version of Tetris was written by Didier Tallot <tallot@bdblues.altair.fr>\nfor X windows with the HP Widgets set.\n");
        printf("Based on the version by Phill Everson <everson@cs.bris.ac.uk>\nand Martyn Shortley <shortley@cs.bris.ac.uk>,\n");
        printf("Based on the version posted to comp.sources.games by Adam Marguilies <vespa@ssyx.ucsc.edu>\n\nLet us know if you like it.\n");
}