Eiyeron Fulmincendii 11 年之前
父节点
当前提交
313618f178
共有 3 个文件被更改,包括 54 次插入14 次删除
  1. 50 1
      hexagon.c
  2. 1 12
      init_states.c
  3. 3 1
      struct.h

+ 50 - 1
hexagon.c

@@ -9,7 +9,11 @@
 
 int AddIn_main(int isAppli, unsigned short OptionNum)
 {
+    const FONTCHARACTER filename[] = {'\\', '\\', 'f', 'l', 's', '0', '\\', 'S', 'H', 'C', '.', 's', 'a', 'v', 0};
+    const filesize = sizeof(float) * 6;
     Game_Data data;
+    int i;
+    float buffer[6] = {0};
 	// variables for fps calculation
     unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks();
 	// char string to display the fps
@@ -20,7 +24,38 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
     // Key init
     data.shift_latch_value = 0;
     data.alpha_latch_value = 0;
-    data.are_entries_loaded = 0;
+
+    data.entry_highscores = NULL;
+    data.entry_highscores = malloc(sizeof(float) * 6);
+    if(data.entry_highscores == NULL)
+        return 1;
+
+
+    data.is_save_feature_enabled = 1;
+    data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_READ);
+    if(data.fileHandle == IML_FILEERR_ENTRYNOTFOUND) {
+        void;
+    } else if(data.fileHandle>= 0) {
+        if(Bfile_ReadFile(data.fileHandle, (char*)data.entry_highscores, filesize, -1) < 0)
+            data.is_save_feature_enabled = 0;
+        Bfile_CloseFile(data.fileHandle);
+        Bfile_DeleteFile(filename);
+    } else
+    data.is_save_feature_enabled = 0;
+
+
+    if(!data.is_save_feature_enabled){
+        for(i = 0; i < 6; i++) {
+            data.entry_highscores[i] = 0.0f;
+        }
+    }
+
+    data.entry_difficulties = NULL;
+    data.entry_difficulties = malloc(sizeof(char*) * 6);
+    if(data.entry_difficulties == NULL)
+        return 1;
+    load_difficulty_names(data.entry_difficulties);
+
 
     switch_to_state(TITLE, &data);
 
@@ -48,6 +83,20 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
         Sleep(1/0.06);
     }
 
+    if(data.is_save_feature_enabled) {
+        Bfile_CreateFile(filename, filesize);
+        data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_WRITE);
+        if(Bfile_WriteFile(data.fileHandle, (char*)data.entry_highscores, filesize) < 0) {
+            int why;
+            locate(1,1);
+            Print("POURQUOI");
+            GetKey(&why);
+        }
+        Bfile_CloseFile(data.fileHandle);
+   }
+
+    free(data.entry_highscores);
+
     return 1;
 }
 

+ 1 - 12
init_states.c

@@ -1,5 +1,6 @@
 #include "init_states.h"
 #include "pattern.h"
+#include "fxlib.h"
 
 const unsigned char patternTest1[] = {
 	0x0F,    0x00, 0x60,
@@ -254,18 +255,6 @@ void init_menu(Game_Data *data)
 	data->nb_entries = 6;
 	data->current_entry = 1;
 	data->current_entry_high_score = 0; //to load from a save file
-	if(!data->are_entries_loaded) {
-		data->are_entries_loaded = 1;
-		data->entry_difficulties = NULL;
-		data->entry_highscores = NULL;
-		data->entry_difficulties = malloc(sizeof(char*) * 6);
-		data->entry_highscores = malloc(sizeof(float) * 6);
-		if(data->entry_difficulties == NULL || data->entry_highscores == NULL)
-			return;
-		for(i = 0; i < 6; i++)
-			data->entry_highscores[i] = 0.0f;
-		load_difficulty_names(data->entry_difficulties);
-	}
 }
 
 void init_game_over(Game_Data *data)

+ 3 - 1
struct.h

@@ -111,11 +111,13 @@ struct Game_Data{
 	unsigned int nb_entries;
 	unsigned int current_entry; //from 1 to 6
 	unsigned int current_entry_high_score;
-	char are_entries_loaded;
 	char **entry_difficulties; //a table of null-terminated strings
 	float *entry_highscores;
 	char it_s_a_highscore; // IT'S A HIGSCORE!
 	unsigned int keypress_delay;
+
+	char is_save_feature_enabled;
+	int fileHandle;
 };
 
 struct Pattern{