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

⟦cb76dfb3f⟧ TextFile

    Length: 5207 (0x1457)
    Types: TextFile
    Names: »score.c«

Derivation

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

TextFile

#include "defs.h"

update_highscore_table()
{
        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();

        /* Next line finds score greater than current one */
        for (i = 0; ((i < HIGH_TABLE_SIZE) && (score >= high_scores[i].score)); i++);
        i--;
        score_position = 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;
        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);
                panel_set(high_score_item[HIGH_TABLE_SIZE - i], PANEL_LABEL_BOLD, FALSE, PANEL_LABEL_STRING, buf, 0);
        }
        if (score_position != -1)
                panel_set(high_score_item[HIGH_TABLE_SIZE - score_position], PANEL_LABEL_BOLD, TRUE, 0);
        window_set(score_frame, WIN_SHOW, TRUE, 0);
}

print_authors()
{
        printf("This version of tetris was written by Phill Everson <everson@cs.bris.ac.uk>\nand Martyn Shortley <shortley@cs.bris.ac.uk>, ");
        printf("Based on the version posted\nto comp.sources.games by Adam Marguilies <vespa@ssyx.ucsc.edu>\n\nLet us know if you like it.\n31st March 1989 \n");
}