int main(void) { int linesInPropertyFile = 0; struct property **arrayForProperties = 0; struct player **arrayForPlayers = 0; int totalLinesInPropFile = 0; int amntPlayers = 0; int *cornerPositions = malloc(sizeof(int) * SIDES); //Open /dev/urandom for rollDice FILE *propertyFile = fopen("/home/jordan/Documents/Programming/Monopoly Project/properties","rb"); if(propertyFile == NULL) { puts("ERROR: error in opening file(s)"); return 1; } linesInPropertyFile = amountOfLines(propertyFile,&totalLinesInPropFile); /*//DEBUG printf("%d is contained within \"linesInPropertyFile\"\n",linesInPropertyFile);*/ if(createArrayOfPtrs(linesInPropertyFile,(void ***)&arrayForProperties)) { puts("ERROR: error from createArrayOfPointers() :: non-zero returned"); return 1; } /*//DEBUG printf("Outside Pointer: %p\n",arrayForProperties);*/ if(makeArryOfPropertyPtrs(linesInPropertyFile,arrayForProperties)) { puts("ERROR: error from createArrayOfPointersForProperties() :: non-zero returned"); return 1; } if(FillArryPropertyData(arrayForProperties,linesInPropertyFile,propertyFile)) { puts("ERROR: error from FillArryPropertyData() :: non-zero returned"); } if(setupTmpPropertyNames(arrayForProperties,linesInPropertyFile)) { puts("ERROR: error from setupTmpPropertyNames() :: non-zero returned"); } if(setupPlayers(&arrayForPlayers,&amntPlayers)) { puts("ERROR: error from setupPlayers() :: non-zero returned"); } setFourCorners(linesInPropertyFile,cornerPositions); addCorners(linesInPropertyFile,cornerPositions,&arrayForProperties); //Set up GrahicalLoop thread. pthread_t glThread; volatile int isRunning = 1; void* data[4]; data[0] = (void*)arrayForProperties; data[1] = (void*)arrayForPlayers; data[2] = (void*)&linesInPropertyFile; data[3] = (void*)&isRunning; pthread_create(&glThread,NULL,graphicalMain,(void *)data); if(gameLoop(arrayForProperties,arrayForPlayers,linesInPropertyFile,amntPlayers,cornerPositions,&isRunning)) { puts("ERROR: error from gameLoop() :: non-zero returned"); } //DEBUG /*printf("array: %p\n",arrayForProperties); printf("*array: %p\n",*arrayForProperties); printf("Lines W/O comments: %d Total lines comments: %d\n\n",linesInPropertyFile,totalLinesInPropFile); int i = 0; for(i = 0;i < 4;i++) { printf("CORNER POSITION #%d: %d\n",i,cornerPositions[i]); } for(i = 0;i < linesInPropertyFile;i++) { printf("NAME: %s\n",(arrayForProperties[i])->name); printf("MONEY: %d\n",(arrayForProperties[i])->value); } puts(""); for(i = 0;i < amntPlayers;i++) { printf("NAME: %s\n",(arrayForPlayers[i])->id); printf("MONEY: %d\n",(arrayForPlayers[i])->money); }*/ //free allocated memory int i = 0; for(i = 0;i < linesInPropertyFile + SIDES;i++) { if((arrayForProperties[i])->type != 1) { free((arrayForProperties[i])->name); } free(arrayForProperties[i]); } free(arrayForProperties); for(i = 0;i < amntPlayers;i++) { free((arrayForPlayers[i])->id); free(arrayForPlayers[i]); } free(arrayForPlayers); //Close FILE stream for /dev/urandom fclose(propertyFile); return 0; }
const char* lineFromTheBack(size_t lineNumberFromTheBack) { return line(amountOfLines() - (lineNumberFromTheBack - 1)); }