Initial work on score with files.
authorlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Sun, 11 Feb 2007 03:39:54 +0000 (03:39 +0000)
committerlimb <limb@bc5cbbab-a4ec-0310-bb52-ff3d296db539>
Sun, 11 Feb 2007 03:39:54 +0000 (03:39 +0000)
Currently broken.
Split into 2 files, scores and names.  Do scores first.

git-svn-id: svn+ssh://svn/var/repos/curfender@634 bc5cbbab-a4ec-0310-bb52-ff3d296db539

main.cpp

index d19c525..d55e17e 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -22,6 +22,7 @@
 #include <cstring>
 #include <cstdlib>
 #include <time.h>
+#include <cstdio>
 
 const int podmax = 8;
 const int bulletmax = 10;
@@ -60,6 +61,15 @@ struct game_object {
   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;
@@ -940,7 +950,36 @@ int main(){
 
   //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]);
+    };
+  };
+  
+  //strcpy(hname, "limb");//debug
 
+  mvprintw(13,34,"High Score: %s %d",hname,hscore);
+  
   //get the cursor out of the way
   mvprintw(23,79,"-");