1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*
Copyright notice:
This is mine. I'm only letting you use it. Period. Feel free to rip off
any of the code you see fit, but have the courtesy to give me credit.
Otherwise great hairy beasties will rip your eyes out and eat your flesh
when you least expect it.
Jonny Goldman <jonathan@think.com>
Wed May 8 1991
*/
/* score.c -- Print the score. */
#include "vaders.h"
#include <sys/types.h>
#include <sys/stat.h>
#define SCORELABEL 10
#define SCOREPOS (SCORELABEL+15)
#define HILABEL (SCOREPOS+20)
#define HIPOS (HILABEL+15)
char *scorestr=NULL,*highstr=NULL;
static int painthiscore=0;
int hiscore = -1;
int initial_hiscore=0;
void PaintScore()
{
char scorestring[8];
if (!scorestr) {
scorestr=strdup(_("Score"));
highstr=strdup(_("High"));
}
XDrawImageString(dpy, labelwindow, scoregc, 0, SCORELABEL, scorestr, strlen(scorestr));
sprintf(scorestring, "%6d ", score);
XDrawImageString(dpy, labelwindow, scoregc, 0, SCOREPOS, scorestring, 7);
if (nextbonus && score >= nextbonus) {
basesleft++;
ShowBase(basesleft-1, basegc);
bases = basesleft;
nextbonus = 0;
}
if (painthiscore || (score > hiscore && (hiscore = score)) )
painthiscore=0;
sprintf(scorestring, "%6d ", hiscore);
XDrawImageString(dpy, labelwindow, scoregc, 0, HILABEL, highstr, strlen(highstr));
XDrawImageString(dpy, labelwindow, scoregc, 0, HIPOS, scorestring, 7);
}
void InitScore()
{
score = 0;
if (hiscore == -1)
{
FILE *f;
char l[15];
painthiscore = 1;
f=fopen("/var/lib/games/xinvaders","r");
if (f)
{
if (fgets(l,14,f) != NULL)
initial_hiscore=hiscore=atoi(l);
else
hiscore=0;
fclose(f);
} else
hiscore=0;
}
basesleft = 3;
nextbonus = 1500;
}
void SaveScore()
{
FILE *f;
if((initial_hiscore != hiscore) && (f=fopen("/var/lib/games/xinvaders","w")))
{
fchmod(fileno(f),S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
fprintf(f,"%d\n",hiscore);
fclose(f);
}
}
|