#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#include "define.h"
#include "schemaGameUtility.h"
Go to the source code of this file.
Data Structures | |
struct | gameRecordValues |
Data struct containing the game's records. More... | |
Functions | |
char ** | readfile (char namefile[], bool *schema_ok, unsigned int *mapCurrentRow, unsigned int *mapCurrentCol, unsigned int mapMaxRow, unsigned int mapMaxCol, bool differentColLen) |
This function manages dinamic data loading processing from the configuration file. | |
char ** | allocResetVariable (unsigned int mapMaxRow, unsigned int mapMaxCol) |
Allocs and reset the variable that will contains file content. | |
void | skipCharacters (char *fileChar, int *checkchar, FILE *file2read) |
Skips all the EOF, ENDLINE and COMMENT characters. | |
bool | readCharacters (unsigned int *mapCurrentCol, unsigned int mapMaxCol, const unsigned int *mapCurrentRow, unsigned int mapMaxRow, char **contentFile, FILE *file2read) |
If there aren't structural form error in file and while the file not end, reads all the characters and puts it into variable contentFile. | |
bool | checkDifferentColLen (const unsigned int *mapCurrentRow, const unsigned int *mapCurrentCol, unsigned int *checkCol) |
Check if all the rows in the file has the same number of columns. | |
bool | setGameRecordStructValue (char **filecontent, unsigned int numrow, unsigned int numcol) |
Save the game record list into the record data structure, checking characters using function isallowedchar. | |
bool | readSetGameRecord (unsigned int *readrows) |
Read from record file the record list and save it in the record data struct, invoking the functions readfile and setGameRecordStructValue. | |
void | save_record (const char *name, unsigned int totalpoints, unsigned int currentlevel) |
Save the new record in file, invoking the function readSetGameRecord. | |
void | printschema () |
Simple function that print on standard output the content of a matrix with the dimensions row x column in textual format (char). | |
Variables | |
struct gameRecordValues | gameRecord [MAX_RECORD_SHOW] |
Data struct containing the game's records. |
Definition in file gameIOManager.h.
char** allocResetVariable | ( | unsigned int | mapMaxRow, | |
unsigned int | mapMaxCol | |||
) |
Allocs and reset the variable that will contains file content.
mapMaxRow | max row length | |
mapMaxCol | max column length |
Definition at line 98 of file gameIOManager.c.
Referenced by readfile().
bool checkDifferentColLen | ( | const unsigned int * | mapCurrentRow, | |
const unsigned int * | mapCurrentCol, | |||
unsigned int * | checkCol | |||
) |
Check if all the rows in the file has the same number of columns.
mapCurrentRow | row position | |
mapCurrentCol | column position | |
checkCol | Reference number of columns |
Definition at line 189 of file gameIOManager.c.
References D1.
Referenced by readfile().
void printschema | ( | ) |
Simple function that print on standard output the content of a matrix with the dimensions row x column in textual format (char).
It works only in debug modality. Warning: this function doesn't implement any sort of control on input data; make sure that are correct!
Definition at line 438 of file gameIOManager.c.
References D1, schemaProp::gameMap, schemaProp::numCol, schemaProp::numRow, and schemaData.
Referenced by newgame().
bool readCharacters | ( | unsigned int * | mapCurrentCol, | |
unsigned int | mapMaxCol, | |||
const unsigned int * | mapCurrentRow, | |||
unsigned int | mapMaxRow, | |||
char ** | contentFile, | |||
FILE * | file2read | |||
) |
If there aren't structural form error in file and while the file not end, reads all the characters and puts it into variable contentFile.
mapCurrentCol | column position | |
mapMaxCol | max column length | |
mapCurrentRow | row position | |
mapMaxRow | max row length | |
contentFile | content of the file | |
file2read | pointer to the opened file to read |
Definition at line 142 of file gameIOManager.c.
Referenced by readfile().
char** readfile | ( | char | namefile[], | |
bool * | schema_ok, | |||
unsigned int * | mapCurrentRow, | |||
unsigned int * | mapCurrentCol, | |||
unsigned int | mapMaxRow, | |||
unsigned int | mapMaxCol, | |||
bool | differentColLen | |||
) |
This function manages dinamic data loading processing from the configuration file.
It ignores the comments ( COMMENT ) and lines that contain less then one characters ( successives ENDLINE ). It allocates just the same memory of 'maxrow' and 'maxcol' (array of strings), because it also implements lenght controls. An addittive control, that verify if all the rows have the same number of columns, should be activate setting 'diffcontrol' to TRUE. Note: It isn't necessary to modify this function, although if the need arises to change the structure of the file. It invokes allocResetVariable, skipCharacters, readCharacters and checkDifferentColLen functions.
namefile | file name | |
schema_ok | error control | |
mapCurrentRow | row position | |
mapCurrentCol | column position | |
mapMaxRow | max row length | |
mapMaxCol | max column length | |
differentColLen | activate different columns length control |
Definition at line 9 of file gameIOManager.c.
References allocResetVariable(), checkDifferentColLen(), COMMENT, D1, D2, ENDLINE, readCharacters(), and skipCharacters().
Referenced by loadCheckGame(), and readSetGameRecord().
bool readSetGameRecord | ( | unsigned int * | readrows | ) |
Read from record file the record list and save it in the record data struct, invoking the functions readfile and setGameRecordStructValue.
readrows | Number of record read |
Definition at line 211 of file gameIOManager.c.
References D1, D2, MAX_RECORD_SHOW, MAX_RECORDNAME_LEN, readfile(), RECORD_FILE_NAME, and setGameRecordStructValue().
Referenced by save_record(), and show_records().
void save_record | ( | const char * | name, | |
unsigned int | totalpoints, | |||
unsigned int | currentlevel | |||
) |
Save the new record in file, invoking the function readSetGameRecord.
Warning: this function work properly with inputs composed only by letters, digits, COMMENT and ENDLINE.
name | Player name | |
totalpoints | Total won points | |
currentlevel | Reached level |
Definition at line 348 of file gameIOManager.c.
References D1, D2, D3, gameRecord, MAX_RECORD_SHOW, readSetGameRecord(), and RECORD_FILE_NAME.
Referenced by win().
bool setGameRecordStructValue | ( | char ** | filecontent, | |
unsigned int | numrow, | |||
unsigned int | numcol | |||
) |
Save the game record list into the record data structure, checking characters using function isallowedchar.
filecontent | Content of the file | |
numrow | Number of rows | |
numcol | Number of columns |
Definition at line 266 of file gameIOManager.c.
References D1, DIGITS, gameRecord, isallowedchar(), gameRecordValues::level, LOWERCASE, NEW_GAME_ROUND, gameRecordValues::points, and UPPERCASE.
Referenced by readSetGameRecord().
void skipCharacters | ( | char * | fileChar, | |
int * | checkchar, | |||
FILE * | file2read | |||
) |
Skips all the EOF, ENDLINE and COMMENT characters.
fileChar | Readed character | |
checkchar | Integer value of the readed character | |
file2read | pointer to the opened file to read |
Definition at line 124 of file gameIOManager.c.
Referenced by readfile().
struct gameRecordValues gameRecord[MAX_RECORD_SHOW] |
Data struct containing the game's records.
Referenced by save_record(), setGameRecordStructValue(), and show_records().