home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 7 Games
/
07-Games.zip
/
MVTREK.ZIP
/
HISCORE.C
next >
Wrap
C/C++ Source or Header
|
1989-12-26
|
2KB
|
128 lines
#include "vtrek.h"
#define SCOREFILE "vtrek.scr"
/*
* score -- figure score and post it.
*/
struct sc_ent {
char sc_name[80];
char sc_ship[80];
int sc_level;
} top_ten[10];
score(win)
int win;
{
FILE *fp;
int i;
int j;
int killrate;
float rate;
/*
* Open file and read list
*/
if ((fp = fopen(SCOREFILE, "r+")) == (FILE *)NULL)
{
fprintf(stderr, "Cannot access scorefile\n");
return;
}
for (i = 0; i < 10; i++)
{
for (j = 0; j < 80 ; j++)
{
top_ten[i].sc_name[j] = ' ';
top_ten[i].sc_ship[j] = ' ';
}
top_ten[i].sc_level = 0;
}
scload(fp, top_ten);
/*
* Insert her in list if need be
*/
if (win > 0)
{
if (stardate == begdate)
killrate = 0;
else
{
rate = (begkling - numkling)/(stardate - begdate);
killrate = (int)(rate * 500 * (skill + 1)/2);
}
for (i = 0; i < 10; i++)
if (killrate > top_ten[i].sc_level) break;
if (i < 10)
{
for (j = 9; j > i; j--)
top_ten[j] = top_ten[j-1];
top_ten[i].sc_level = killrate;
strcpy(top_ten[i].sc_name, captain);
strcpy(top_ten[i].sc_ship, shipname);
}
}
/*
* Print the list
*/
printf("\nTop Ten Trekkies\nScore\t\tName\t\tShip\n");
for (i = 0; i < 10; i++)
if (top_ten[i].sc_level)
printf("%8d\t%-16s%s\n",
top_ten[i].sc_level,
top_ten[i].sc_name,
top_ten[i].sc_ship);
if (win > 0)
{
fseek(fp, 0L, 0);
scdump(fp, top_ten);
}
fclose(fp);
}
scload(fp, rec)
FILE *fp;
struct sc_ent rec[];
{
int i;
i = 0;
while
(
fscanf
(
fp,
"%d %s %s",
&(rec[i].sc_level),
rec[i].sc_name,
rec[i].sc_ship
) != EOF &&
i < 10
)
i++;
}
scdump(fp, rec)
FILE *fp;
struct sc_ent rec[];
{
int i;
i = 0;
while (i < 10 && rec[i].sc_level > 0)
{
fprintf
(
fp,
"%d %s %s\n",
rec[i].sc_level,
rec[i].sc_name,
rec[i].sc_ship
);
i++;
}
}