author | ecalot
<ecalot> 2005-02-22 11:34:59 UTC |
committer | ecalot
<ecalot> 2005-02-22 11:34:59 UTC |
parent | e23a79cb312ba993afe898135043b1a3ea764f2f |
FP/src/include/map_defs.h | +146 | -146 |
FP/src/res/hof.c | +189 | -189 |
FP/src/res/sav.c | +84 | -84 |
diff --git a/FP/src/include/map_defs.h b/FP/src/include/map_defs.h index 59ce7d2..6cf908f 100644 --- a/FP/src/include/map_defs.h +++ b/FP/src/include/map_defs.h @@ -1,146 +1,146 @@ -/***************************************************************\ -| Format Block Specification | -\************************************************************** / - -Len Offs BlockName & Description -1 0 validador (0-1953) -720 1 wall -720 721 back -18 1441 doors1 -238 1459 unknown1 (22/215?) (por convencion: empty para guardar info) -18 1697 doors2 -238 1715 unknown2 (22/215?) (por convencion: empty para guardar info) -96 1953 links -64 2049 unknown3 (peligroso) -3 2113 startPosition (1: screen; 2: module; 3: direction) -3 2116 unknownSP (Dafault: triple 0) (por convencion: 1: comienzo de string info; 2 y 3: Debug Position) -1 2117 startPositionUnknown (direction?) -24 2120 guardPosition -24 2144 guardDirection (00: right; FF: left) -1 2168 unknown4/1 (por convencion: validator 1953-2306) -23 2169 unknown4/23 (por convencion: empty para guardar info) -24 2192 unknown5 (por convencion: empty para guardar info) -24 2216 guardSkill -24 2240 unknown6 (por convencion: empty para guardar info) -24 2264 guardColor -16 2288 unknown7 (por convencion: empty para guardar info) -2 2304 0F 09 - 2306 New Level - -/ **************************************************************\ -| Inclusiones | -\***************************************************************/ - -#ifndef INCLUDED_MAPS_H -#define INCLUDED_MAPS_H - -#include <stdio.h> - -/***************************************************************\ -| Definiciones del Precompilador | -\***************************************************************/ - -#define MAPS_MAX_SCREENS 24 -#define MAPS_MAX_LENGTH 49 -#define MAPS_LINKMAP_CENTER 24 - -#define MAPS_DIRECTION_RIGHT 0x00 -#define MAPS_DIRECTION_LEFT 0xFF - -#define MAPS_BLOCK_SIZEOF_LEVEL 2306 -#define MAPS_BLOCK_OFFSET_LEVELS 6 - -#define MAPS_BLOCK_OFFSET_VALIDATOR_WALL 0 -#define MAPS_BLOCK_SIZEOF_VALIDATOR_WALL 1 -#define MAPS_BLOCK_OFFSET_WALL 1 -#define MAPS_BLOCK_SIZEOF_WALL 720 -#define MAPS_BLOCK_SIZEOF_BACK 720 -#define MAPS_BLOCK_OFFSET_BACK 721 -#define MAPS_BLOCK_OFFSET_LINK 1953 -#define MAPS_BLOCK_OFFSET_VALIDATOR_LINK 2168 -#define MAPS_BLOCK_OFFSET_GUARD_DIRECTION 2144 -#define MAPS_BLOCK_OFFSET_GUARD_POSITION 2120 -#define MAPS_BLOCK_OFFSET_START_POSITION 2113 -#define MAPS_BLOCK_OFFSET_GUARD_SKILL 2216 -#define MAPS_BLOCK_OFFSET_GUARD_COLOR 2264 -#define MAPS_BLOCK_OFFSET_UNKNOWN_1 1459 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_1 238 -#define MAPS_BLOCK_OFFSET_UNKNOWN_2 1715 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_2 238 -#define MAPS_BLOCK_OFFSET_UNKNOWN_4 2169 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_4 23 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_5 24 -#define MAPS_BLOCK_OFFSET_UNKNOWN_5 2192 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_6 24 -#define MAPS_BLOCK_OFFSET_UNKNOWN_6 2240 -#define MAPS_BLOCK_SIZEOF_UNKNOWN_7 16 -#define MAPS_BLOCK_OFFSET_UNKNOWN_7 2288 -#define MAPS_BLOCK_SIZEOF_GATE_1 18 -#define MAPS_BLOCK_SIZEOF_GATE 18 -#define MAPS_BLOCK_OFFSET_GATE_1 1441 -#define MAPS_BLOCK_SIZEOF_GATE_2 18 -#define MAPS_BLOCK_OFFSET_GATE_2 1697 -#define MAPS_BLOCK_SIZEOF_FILE 37031 - - -/* Constantes copadas */ -#define MAPS_sUp 2 -#define MAPS_sDown 3 -#define MAPS_sLeft 0 -#define MAPS_sRight 1 - -#include "tiles.h" - -/* - none 0x00 This value is used allways for this group - free 0x00 +Nothing -Blue line - free 0x01 +Spot1 -No blue line - free 0x02 +Spot2 -Diamond - free 0x03 Window - free 0xFF +Spot3 -Blue line? - spike 0x00 Normal (allows animation) - spike 0x01 Barely Out - spike 0x02 Half Out - spike 0x03 Fully Out - spike 0x04 Fully Out - spike 0x05 Out? - spike 0x06 Out? - spike 0x07 Half Out? - spike 0x08 Barely Out? - spike 0x09 Disabled - gate 0x00 Closed - gate 0x01 Open - tapest 0x00 -With Lattice - tapest 0x01 -Alternative Design - tapest 0x02 -Normal - tapest 0x03 -Black - potion 0x00 Empty - potion 0x01 Health point - potion 0x02 Life - potion 0x03 Feather Fall - potion 0x04 Invert - potion 0x05 Poison - potion 0x06 Open - ttop 0x00 -With lattice - ttop 0x01 -Alernative design - ttop 0x02 -Normal - ttop 0x03 -Black - ttop 0x04 -Black - ttop 0x05 -With alternative design and bottom - ttop 0x06 -With bottom - ttop 0x07 -With window - chomp 0x00 Normal - chomp 0x01 Half Open - chomp 0x02 Closed - chomp 0x03 Partially Open - chomp 0x04 Extra Open - chomp 0x05 Stuck Open - wall 0x00 +Normal -Blue line - wall 0x01 +Normal -No Blue line -*/ - -#define MAP_B_NONE 0 -#define MAP_F_WALL TILE_WALL -#define MAP_F_FREE TILE_EMPTY - -#endif +/***************************************************************\ +| Format Block Specification | +\************************************************************** / + +Len Offs BlockName & Description +1 0 validador (0-1953) +720 1 wall +720 721 back +18 1441 doors1 +238 1459 unknown1 (22/215?) (por convencion: empty para guardar info) +18 1697 doors2 +238 1715 unknown2 (22/215?) (por convencion: empty para guardar info) +96 1953 links +64 2049 unknown3 (peligroso) +3 2113 startPosition (1: screen; 2: module; 3: direction) +3 2116 unknownSP (Dafault: triple 0) (por convencion: 1: comienzo de string info; 2 y 3: Debug Position) +1 2117 startPositionUnknown (direction?) +24 2120 guardPosition +24 2144 guardDirection (00: right; FF: left) +1 2168 unknown4/1 (por convencion: validator 1953-2306) +23 2169 unknown4/23 (por convencion: empty para guardar info) +24 2192 unknown5 (por convencion: empty para guardar info) +24 2216 guardSkill +24 2240 unknown6 (por convencion: empty para guardar info) +24 2264 guardColor +16 2288 unknown7 (por convencion: empty para guardar info) +2 2304 0F 09 + 2306 New Level + +/ **************************************************************\ +| Inclusiones | +\***************************************************************/ + +#ifndef INCLUDED_MAPS_H +#define INCLUDED_MAPS_H + +#include <stdio.h> + +/***************************************************************\ +| Definiciones del Precompilador | +\***************************************************************/ + +#define MAPS_MAX_SCREENS 24 +#define MAPS_MAX_LENGTH 49 +#define MAPS_LINKMAP_CENTER 24 + +#define MAPS_DIRECTION_RIGHT 0x00 +#define MAPS_DIRECTION_LEFT 0xFF + +#define MAPS_BLOCK_SIZEOF_LEVEL 2306 +#define MAPS_BLOCK_OFFSET_LEVELS 6 + +#define MAPS_BLOCK_OFFSET_VALIDATOR_WALL 0 +#define MAPS_BLOCK_SIZEOF_VALIDATOR_WALL 1 +#define MAPS_BLOCK_OFFSET_WALL 1 +#define MAPS_BLOCK_SIZEOF_WALL 720 +#define MAPS_BLOCK_SIZEOF_BACK 720 +#define MAPS_BLOCK_OFFSET_BACK 721 +#define MAPS_BLOCK_OFFSET_LINK 1953 +#define MAPS_BLOCK_OFFSET_VALIDATOR_LINK 2168 +#define MAPS_BLOCK_OFFSET_GUARD_DIRECTION 2144 +#define MAPS_BLOCK_OFFSET_GUARD_POSITION 2120 +#define MAPS_BLOCK_OFFSET_START_POSITION 2113 +#define MAPS_BLOCK_OFFSET_GUARD_SKILL 2216 +#define MAPS_BLOCK_OFFSET_GUARD_COLOR 2264 +#define MAPS_BLOCK_OFFSET_UNKNOWN_1 1459 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_1 238 +#define MAPS_BLOCK_OFFSET_UNKNOWN_2 1715 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_2 238 +#define MAPS_BLOCK_OFFSET_UNKNOWN_4 2169 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_4 23 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_5 24 +#define MAPS_BLOCK_OFFSET_UNKNOWN_5 2192 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_6 24 +#define MAPS_BLOCK_OFFSET_UNKNOWN_6 2240 +#define MAPS_BLOCK_SIZEOF_UNKNOWN_7 16 +#define MAPS_BLOCK_OFFSET_UNKNOWN_7 2288 +#define MAPS_BLOCK_SIZEOF_GATE_1 18 +#define MAPS_BLOCK_SIZEOF_GATE 18 +#define MAPS_BLOCK_OFFSET_GATE_1 1441 +#define MAPS_BLOCK_SIZEOF_GATE_2 18 +#define MAPS_BLOCK_OFFSET_GATE_2 1697 +#define MAPS_BLOCK_SIZEOF_FILE 37031 + + +/* Constantes copadas */ +#define MAPS_sUp 2 +#define MAPS_sDown 3 +#define MAPS_sLeft 0 +#define MAPS_sRight 1 + +#include "tiles.h" + +/* + none 0x00 This value is used allways for this group + free 0x00 +Nothing -Blue line + free 0x01 +Spot1 -No blue line + free 0x02 +Spot2 -Diamond + free 0x03 Window + free 0xFF +Spot3 -Blue line? + spike 0x00 Normal (allows animation) + spike 0x01 Barely Out + spike 0x02 Half Out + spike 0x03 Fully Out + spike 0x04 Fully Out + spike 0x05 Out? + spike 0x06 Out? + spike 0x07 Half Out? + spike 0x08 Barely Out? + spike 0x09 Disabled + gate 0x00 Closed + gate 0x01 Open + tapest 0x00 -With Lattice + tapest 0x01 -Alternative Design + tapest 0x02 -Normal + tapest 0x03 -Black + potion 0x00 Empty + potion 0x01 Health point + potion 0x02 Life + potion 0x03 Feather Fall + potion 0x04 Invert + potion 0x05 Poison + potion 0x06 Open + ttop 0x00 -With lattice + ttop 0x01 -Alernative design + ttop 0x02 -Normal + ttop 0x03 -Black + ttop 0x04 -Black + ttop 0x05 -With alternative design and bottom + ttop 0x06 -With bottom + ttop 0x07 -With window + chomp 0x00 Normal + chomp 0x01 Half Open + chomp 0x02 Closed + chomp 0x03 Partially Open + chomp 0x04 Extra Open + chomp 0x05 Stuck Open + wall 0x00 +Normal -Blue line + wall 0x01 +Normal -No Blue line +*/ + +#define MAP_B_NONE 0 +#define MAP_F_WALL TILE_WALL +#define MAP_F_FREE TILE_EMPTY + +#endif diff --git a/FP/src/res/hof.c b/FP/src/res/hof.c index f5ea221..52aa1e4 100644 --- a/FP/src/res/hof.c +++ b/FP/src/res/hof.c @@ -1,189 +1,189 @@ - -//Programa princed; - -#include <stdio.h> -#include <conio.h> -#include <math.h> - -#define cPath ""/*'d:\juegos\princed\';*/ -#define cFileSav "prince.hof" - -#define HOF_MAX_RECORDS 6 -#define HOF_NAME_SIZE 25 - -typedef struct { - char nombre[HOF_NAME_SIZE+1]; - unsigned short int min; - float sec; - char empty; -}tRec; -typedef struct { - unsigned short int records; - tRec q[HOF_MAX_RECORDS]; -}tHof; - -/* - unsigned char fselectrecord { - unsigned char r; - printf("Select Record: "); - gets(r); - return r; - };*/ - -void mSortHof(tHof *juego) { - tRec aux; - unsigned char i,j; - - for (i=1;i<=(*juego).records;i++) { - for (j=i+1;j<=(*juego).records;j++) { - if (((*juego).q[i].min<(*juego).q[j].min)||(((*juego).q[i].min==(*juego).q[j].min)&&((*juego).q[i].sec<(*juego).q[j].sec))) { - aux=(*juego).q[i]; - (*juego).q[i]=(*juego).q[j]; - (*juego).q[j]=aux; - } - } - } -} -/* -void mEditarHof(tHof *juego;unsigned r:unsigned); - - secs:float; - i:byte; - nombre:char *[25]; - { - printf("Record ",r," name text: "); - gets(nombre); - for( i=0 ; I++; I<= strlen(nombre)-1 ) - juego.q[r].nombre[i]=nombre[i+1]; - for( i=strlen(nombre) ; I++; I<= 24 ) - juego.q[r].nombre[i]=#0; - printf("Record ",r," minutes left: "); - gets(juego.q[r].min); - ++(juego.q[r].min); - printf("Record ",r," seconds left: "); - gets(secs); - juego.q[r].sec=floor(secs*12)+1; - }; -*/ -void mLimpiarHof(tHof *juego) { - char i; - - (*juego).records=0; - for (i=0;i<HOF_MAX_RECORDS;(*juego).q[i++].empty=1); - //Dejo el flag empty en 1 para que no se guarden estos datos -} - -char mBorrarHof(tHof *juego,char selectRecord) { - char i; - - if(((*juego).records)) { - for(i=selectRecord;i<(*juego).records;(*juego).q[i]=(*juego).q[++i]); //adelanta los otros registros - (*juego).q[((*juego).records--)].empty=1; //borra el ultimo - return 1; - } else { - return 0; - } -} - -char mAgregarHof(tHof *juego,unsigned int min,float sec,char nombre[]) { - unsigned char i,j; - - if ((*juego).records++<6) { - //Posicionarse en un registro ordenado - for (i=0;((i<(*juego).records)&&(((*juego).q[i].min<min)||(((*juego).q[i].min==min)&&((*juego).q[i].sec<sec))));i++); - //correr los otros registros - for(j=i+1;j<(*juego).records;(*juego).q[j]=(*juego).q[++j]); - //Guardar el registro - for(j=0;j<=HOF_NAME_SIZE;(*juego).q[i].nombre[j]=nombre[j++]); - (*juego).q[i].sec=sec; - (*juego).q[i].min=min; - (*juego).q[i].empty=0; - - return 1; - } else { - return 0; - } -} - -char mCargarHof(const char* archivo,tHof *juego) { - FILE *fp; - char aux,i; - unsigned short int auxsec; - - if ((fp=fopen(archivo,"rb"))==NULL) { - return 0; - } else { - aux=fread (&(*juego).records, 2,1,fp); - for (i=0;i<HOF_MAX_RECORDS;i++) { - aux=aux&&fread (&(*juego).q[i].nombre,HOF_NAME_SIZE,1,fp); - aux=aux&&fread (&(*juego).q[i].min,2,1,fp); - aux=aux&&fread (&auxsec,2,1,fp); - (*juego).q[i].sec=(((float)(auxsec-1))/12); - (*juego).q[i].empty=0; - (*juego).q[i].nombre[HOF_NAME_SIZE]=0; - } - fclose(fp); - return aux; - } -} - -char mSalvarHof(char* vFile,tHof *juego) { - FILE * pFile; - char aux; - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; - } - static const char empty[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - unsigned short int auxsec; - aux=fwrite (&(*juego).records, 1, 2, pFile); - for (char i=0;i<HOF_MAX_RECORDS;i++) { - if ((*juego).q[i].empty) { - aux=aux&&fwrite (&empty, 1, 29, pFile); - } else { - aux=aux&&fwrite (&(*juego).q[i].nombre, 1, HOF_NAME_SIZE, pFile); - aux=aux&&fwrite (&(*juego).q[i].min, 1, 2, pFile); - auxsec=(floor((*juego).q[i].sec*12)+1); - aux=aux&&fwrite (&auxsec, 1, 2, pFile); - } - } - fclose (pFile); - return aux; -} - -int main() { - tHof game; - int i; - char salir=0; - - salir=!mCargarHof(cFileSav,&game); - while(!salir) { - printf("Prinhof V1.0 (c) 2003 - Enrique P. Calot\n"); - printf("Check for the latest version at http://www.princed.0.net.ar\n"); - printf("Keys:\n\n"); - printf(" L:load prince.hof (loose changes)\n"); - printf(" G:save prince.hof\n"); - printf(" E:edit record (not saved)\n"); - printf(" A:add record (not saved)\n"); - printf(" D:delete record (not saved)\n"); - printf(" S:sort records (not saved)\n"); - printf(" C:clear records (not saved)\n"); - printf(" Q:quit\n\nTotal: %d registros\n\n",game.records); - - for(i=0;i<game.records&&i<HOF_MAX_RECORDS;i++){ - printf("%d) Name: '%s' Time: '%02d:%05.2f'\n",i+1,game.q[i].nombre,game.q[i].min,game.q[i].sec); - }; - - switch(getche()){ - case 'l':printf("jaja %d ohhh",mCargarHof(cFileSav,&game));break; - case 'g':mSalvarHof(cFileSav,&game);break; - case 'q':salir=1;break; - //'e':meditarhof(game,fselectrecord); - case 'a':mAgregarHof(&game,55,45.3,"Enrique P. Calot");break; - case 'd':mBorrarHof(&game,4);break; - case 'c':mLimpiarHof(&game);break; - case 's':mSortHof(&game);break; - } - } - return 1; -} - + +//Programa princed; + +#include <stdio.h> +#include <conio.h> +#include <math.h> + +#define cPath ""/*'d:\juegos\princed\';*/ +#define cFileSav "prince.hof" + +#define HOF_MAX_RECORDS 6 +#define HOF_NAME_SIZE 25 + +typedef struct { + char nombre[HOF_NAME_SIZE+1]; + unsigned short int min; + float sec; + char empty; +}tRec; +typedef struct { + unsigned short int records; + tRec q[HOF_MAX_RECORDS]; +}tHof; + +/* + unsigned char fselectrecord { + unsigned char r; + printf("Select Record: "); + gets(r); + return r; + };*/ + +void mSortHof(tHof *juego) { + tRec aux; + unsigned char i,j; + + for (i=1;i<=(*juego).records;i++) { + for (j=i+1;j<=(*juego).records;j++) { + if (((*juego).q[i].min<(*juego).q[j].min)||(((*juego).q[i].min==(*juego).q[j].min)&&((*juego).q[i].sec<(*juego).q[j].sec))) { + aux=(*juego).q[i]; + (*juego).q[i]=(*juego).q[j]; + (*juego).q[j]=aux; + } + } + } +} +/* +void mEditarHof(tHof *juego;unsigned r:unsigned); + + secs:float; + i:byte; + nombre:char *[25]; + { + printf("Record ",r," name text: "); + gets(nombre); + for( i=0 ; I++; I<= strlen(nombre)-1 ) + juego.q[r].nombre[i]=nombre[i+1]; + for( i=strlen(nombre) ; I++; I<= 24 ) + juego.q[r].nombre[i]=#0; + printf("Record ",r," minutes left: "); + gets(juego.q[r].min); + ++(juego.q[r].min); + printf("Record ",r," seconds left: "); + gets(secs); + juego.q[r].sec=floor(secs*12)+1; + }; +*/ +void mLimpiarHof(tHof *juego) { + char i; + + (*juego).records=0; + for (i=0;i<HOF_MAX_RECORDS;(*juego).q[i++].empty=1); + //Dejo el flag empty en 1 para que no se guarden estos datos +} + +char mBorrarHof(tHof *juego,char selectRecord) { + char i; + + if(((*juego).records)) { + for(i=selectRecord;i<(*juego).records;(*juego).q[i]=(*juego).q[++i]); //adelanta los otros registros + (*juego).q[((*juego).records--)].empty=1; //borra el ultimo + return 1; + } else { + return 0; + } +} + +char mAgregarHof(tHof *juego,unsigned int min,float sec,char nombre[]) { + unsigned char i,j; + + if ((*juego).records++<6) { + //Posicionarse en un registro ordenado + for (i=0;((i<(*juego).records)&&(((*juego).q[i].min<min)||(((*juego).q[i].min==min)&&((*juego).q[i].sec<sec))));i++); + //correr los otros registros + for(j=i+1;j<(*juego).records;(*juego).q[j]=(*juego).q[++j]); + //Guardar el registro + for(j=0;j<=HOF_NAME_SIZE;(*juego).q[i].nombre[j]=nombre[j++]); + (*juego).q[i].sec=sec; + (*juego).q[i].min=min; + (*juego).q[i].empty=0; + + return 1; + } else { + return 0; + } +} + +char mCargarHof(const char* archivo,tHof *juego) { + FILE *fp; + char aux,i; + unsigned short int auxsec; + + if ((fp=fopen(archivo,"rb"))==NULL) { + return 0; + } else { + aux=fread (&(*juego).records, 2,1,fp); + for (i=0;i<HOF_MAX_RECORDS;i++) { + aux=aux&&fread (&(*juego).q[i].nombre,HOF_NAME_SIZE,1,fp); + aux=aux&&fread (&(*juego).q[i].min,2,1,fp); + aux=aux&&fread (&auxsec,2,1,fp); + (*juego).q[i].sec=(((float)(auxsec-1))/12); + (*juego).q[i].empty=0; + (*juego).q[i].nombre[HOF_NAME_SIZE]=0; + } + fclose(fp); + return aux; + } +} + +char mSalvarHof(char* vFile,tHof *juego) { + FILE * pFile; + char aux; + if ((pFile = fopen (vFile , "wb"))==NULL) { + return 0; + } + static const char empty[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + unsigned short int auxsec; + aux=fwrite (&(*juego).records, 1, 2, pFile); + for (char i=0;i<HOF_MAX_RECORDS;i++) { + if ((*juego).q[i].empty) { + aux=aux&&fwrite (&empty, 1, 29, pFile); + } else { + aux=aux&&fwrite (&(*juego).q[i].nombre, 1, HOF_NAME_SIZE, pFile); + aux=aux&&fwrite (&(*juego).q[i].min, 1, 2, pFile); + auxsec=(floor((*juego).q[i].sec*12)+1); + aux=aux&&fwrite (&auxsec, 1, 2, pFile); + } + } + fclose (pFile); + return aux; +} + +int main() { + tHof game; + int i; + char salir=0; + + salir=!mCargarHof(cFileSav,&game); + while(!salir) { + printf("Prinhof V1.0 (c) 2003 - Enrique P. Calot\n"); + printf("Check for the latest version at http://www.princed.0.net.ar\n"); + printf("Keys:\n\n"); + printf(" L:load prince.hof (loose changes)\n"); + printf(" G:save prince.hof\n"); + printf(" E:edit record (not saved)\n"); + printf(" A:add record (not saved)\n"); + printf(" D:delete record (not saved)\n"); + printf(" S:sort records (not saved)\n"); + printf(" C:clear records (not saved)\n"); + printf(" Q:quit\n\nTotal: %d registros\n\n",game.records); + + for(i=0;i<game.records&&i<HOF_MAX_RECORDS;i++){ + printf("%d) Name: '%s' Time: '%02d:%05.2f'\n",i+1,game.q[i].nombre,game.q[i].min,game.q[i].sec); + }; + + switch(getche()){ + case 'l':printf("jaja %d ohhh",mCargarHof(cFileSav,&game));break; + case 'g':mSalvarHof(cFileSav,&game);break; + case 'q':salir=1;break; + //'e':meditarhof(game,fselectrecord); + case 'a':mAgregarHof(&game,55,45.3,"Enrique P. Calot");break; + case 'd':mBorrarHof(&game,4);break; + case 'c':mLimpiarHof(&game);break; + case 's':mSortHof(&game);break; + } + } + return 1; +} + diff --git a/FP/src/res/sav.c b/FP/src/res/sav.c index b980b98..ae352fc 100644 --- a/FP/src/res/sav.c +++ b/FP/src/res/sav.c @@ -1,84 +1,84 @@ -/* -Range values: - -Minutes remining [0 to 32766 for minutes; 32767 to 65534 for NO TIME; 65535 for game over] -Seconds remining [0.000 to 59.916] rounded by units of 0.0833333 -Level [1 to 12 for normal levels; 13 for 12bis; 14 for princess; 15 for posion level] -Lives [0 (not recomended), 1 to 65535] -*/ - - -//types -typedef struct { - unsigned short int minleft; - unsigned short int secleft; - unsigned short int level; - unsigned short int lives; -}tSav; - -//Includes -#include <math.h> -#include <stdio.h> - -//Prototypes - -char mSaveSAV(char* vFile,tSav* vSav); -char mLoadSAV(char* vFile,tSav* vSav); -void mGetGame(tSav* vSav,unsigned short int *min,float *sec,unsigned short int *level,unsigned short int *lives); -void mSetGame(tSav* vSav,unsigned short int min,float sec,unsigned short int level,unsigned short int lives); - -//Implementation -char mSaveSAV(char* vFile,tSav* vSav) { - FILE * pFile; - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; - } - fwrite (vSav, 1, 8, pFile); - fclose (pFile); - return 1; -} - -char mLoadSAV(char* vFile,tSav* vSav) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - aux=fread (vSav,8,1,fp); - fclose(fp); - return aux; - } -} - -void mGetGame(tSav* vSav,unsigned short int *min,float *sec,unsigned short int *level,unsigned short int *lives) { - *sec=(((float)(((*vSav).secleft)-1))/12); - *min=(*vSav).minleft-1; - *level=(*vSav).level; - *lives=(*vSav).lives; -} - -void mSetGame(tSav* vSav,unsigned short int min,float sec,unsigned short int level,unsigned short int lives) { - (*vSav).secleft=(floor(sec*12)+1); - (*vSav).minleft=min+1; - (*vSav).level=level; - (*vSav).lives=lives; -} - -//main test program -#include <conio.h> -void main (){ - tSav vSav; - unsigned short int min; - float sec; - unsigned short int level; - unsigned short int lives; - printf("kaka: %d jaja.\n",mLoadSAV("prince.sav",&vSav)); - mGetGame(&vSav,&min,&sec,&level,&lives); - printf("Min: %d. Sec: %f. Level: %d. Lives: %d.\n",min,sec,level,lives); - //mSetGame(&vSav,0,35,5,7); - //mSaveSAV("prince.sav",&vSav); - - - getche(); -}; +/* +Range values: + +Minutes remining [0 to 32766 for minutes; 32767 to 65534 for NO TIME; 65535 for game over] +Seconds remining [0.000 to 59.916] rounded by units of 0.0833333 +Level [1 to 12 for normal levels; 13 for 12bis; 14 for princess; 15 for posion level] +Lives [0 (not recomended), 1 to 65535] +*/ + + +//types +typedef struct { + unsigned short int minleft; + unsigned short int secleft; + unsigned short int level; + unsigned short int lives; +}tSav; + +//Includes +#include <math.h> +#include <stdio.h> + +//Prototypes + +char mSaveSAV(char* vFile,tSav* vSav); +char mLoadSAV(char* vFile,tSav* vSav); +void mGetGame(tSav* vSav,unsigned short int *min,float *sec,unsigned short int *level,unsigned short int *lives); +void mSetGame(tSav* vSav,unsigned short int min,float sec,unsigned short int level,unsigned short int lives); + +//Implementation +char mSaveSAV(char* vFile,tSav* vSav) { + FILE * pFile; + if ((pFile = fopen (vFile , "wb"))==NULL) { + return 0; + } + fwrite (vSav, 1, 8, pFile); + fclose (pFile); + return 1; +} + +char mLoadSAV(char* vFile,tSav* vSav) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + aux=fread (vSav,8,1,fp); + fclose(fp); + return aux; + } +} + +void mGetGame(tSav* vSav,unsigned short int *min,float *sec,unsigned short int *level,unsigned short int *lives) { + *sec=(((float)(((*vSav).secleft)-1))/12); + *min=(*vSav).minleft-1; + *level=(*vSav).level; + *lives=(*vSav).lives; +} + +void mSetGame(tSav* vSav,unsigned short int min,float sec,unsigned short int level,unsigned short int lives) { + (*vSav).secleft=(floor(sec*12)+1); + (*vSav).minleft=min+1; + (*vSav).level=level; + (*vSav).lives=lives; +} + +//main test program +#include <conio.h> +void main (){ + tSav vSav; + unsigned short int min; + float sec; + unsigned short int level; + unsigned short int lives; + printf("kaka: %d jaja.\n",mLoadSAV("prince.sav",&vSav)); + mGetGame(&vSav,&min,&sec,&level,&lives); + printf("Min: %d. Sec: %f. Level: %d. Lives: %d.\n",min,sec,level,lives); + //mSetGame(&vSav,0,35,5,7); + //mSaveSAV("prince.sav",&vSav); + + + getche(); +};