char radar[1]; //radar symbol
};
-int high_score(){
-
- return score;
-};
-
-void record_score(int score){
-
-};
-
int check_collision(game_object object1, game_object object2){
int collided = 0;
int spacing = 2;
halfdelay(1);
} else {
pause = 0;
+
+ //record score if high
+
+ int hscore = 0;
+ char filename[250];
+ char outstring[50];
+ strcpy (filename, "/.curfender_scores");
+ char home[250];
+ strcpy(home, getenv("HOME"));
+
+ strncat(home, filename, 20);
+
+ FILE *scorefile = fopen(home, "r");
+ char workchara[6];
+ fgets(workchara, 6, scorefile);
+ hscore = atoi(workchara);
+ fclose(scorefile);
+
+ if(score>hscore){
+ FILE *writescorefile = fopen(home, "w");
+ sprintf(outstring, "%d", score);
+ fputs(outstring, writescorefile);
+ fclose(writescorefile);
+ };
+
while(pause!=' '){
cbreak();
mvprintw(10,20,"GAME OVER. Score:%d Press SPACE to exit.\n", score);
+ if(score>hscore){
+ mvprintw(11,20,"High Score: %s", outstring);
+ };
pause = getch();
};
endwin();
//high score
int hscore = 0;
- int hscores[10];
- char hname[15];
- char hnames[10][15];
- //char hold[200];
- char hold[20];
- FILE *scorefile = fopen("/var/games/curfender/scores", "r"); //might want to handle failure, eventually
- for(int x=0;x<10;x++){
- char *workchara;
- char *workcharb;
- fgets(hold, 20, scorefile);
- workchara = strtok(hold, " ");
- workcharb = strpbrk(hold, " ");
- //strncpy(workchara, hold, 5);
- //strncpy(workcharb, hold, 15);
- hscores[x] = atoi(workchara);
- strcpy(hnames[x], workcharb);
- };
- fclose(scorefile);
- for(int x=0;x<10;x++){
- if(hscores[x]>hscore){
- hscore=hscores[x];
- strcpy(hname,hnames[x]);
- };
+ char filename[250];
+ strcpy (filename, "/.curfender_scores");
+ char home[250];
+ strcpy(home, getenv("HOME"));
+
+ strncat(home, filename, 20);
+
+ if(FILE *scorefile = fopen(home, "r")){
+ char workchara[6];
+ fgets(workchara, 6, scorefile);
+ hscore = atoi(workchara);
+ fclose(scorefile);
+ } else {
+ FILE *scorefile = fopen(home, "w");
+ fputs("0\n", scorefile);
+ fclose(scorefile);
+ hscore = 0;
};
- //strcpy(hname, "limb");//debug
-
- mvprintw(13,34,"High Score: %s %d",hname,hscore);
+ mvprintw(13,34,"High Score: %d",hscore);
//get the cursor out of the way
mvprintw(23,79,"-");