void GAStatistics::flushScores(){ if(nscrs == 0) return; writeScores(); memset(gen, 0, Nscrs*sizeof(int)); memset(aveScore, 0, Nscrs*sizeof(float)); memset(maxScore, 0, Nscrs*sizeof(float)); memset(minScore, 0, Nscrs*sizeof(float)); memset(devScore, 0, Nscrs*sizeof(float)); memset(divScore, 0, Nscrs*sizeof(float)); nscrs = 0; }
void GameScores::addScore(Score score) { for (int i = 0; i < MAX_SCORES; i++) { if ( !scores[i].valid || scores[i].score < score.score) { for (int j = MAX_SCORES - 1; j > i; j--) { memcpy(scores[j].name, scores[j - 1].name, strlen(scores[j - 1].name)); scores[j].score = scores[j - 1].score; scores[j].valid = scores[j - 1].valid; } memcpy(scores[i].name, score.name, strlen(score.name)); scores[i].score = score.score; scores[i].valid = true; break; } } writeScores(); }
void drawGameScreen() { clear(); //draw exterior of game drawBox(10, 3, 44, 34, 0); //draw path walls drawBox(10, 7, 11, 3, 0); drawBox(18, 7, 4, 14, 0); drawBox(18, 18, 16, 3, 0); drawBox(31, 7, 4, 14, 0); drawBox(31, 7, 18, 3, 0); drawBox(46, 7, 4, 24, 0); drawBox(19, 28, 30, 3, 0); drawBox(19, 28, 4, 9, 0); //fix up the corners clearPath(); fixCorners(); //add beginning and ending chars mvaddch(8, 8, '>'); mvaddch(37, 21, ACS_DARROW); //draw and fill the purchase portion of the screen attron(COLOR_PAIR(0)); drawPurchaseArea(); basicSetupScreen(1); updateScore(0); attroff(COLOR_PAIR(0)); drawTowerExplain(); //load arrays for drawing TowerArray* theTowerList = getTowerArray("assets/towersLevel1.txt"); Path* thePath = getPathArray("assets/path.txt"); UnitListHeader * unitList = malloc(sizeof(UnitListHeader)); int moneyAmount = STARTINGMONEY; initializeList(unitList); drawUnitTypes(unitList); int theScore = 0; drawTowers(theTowerList); //go to entering unit purchases (gives control back to user) selectUnitsInterface(thePath,unitList,&moneyAmount,theTowerList,&theScore); //get lowest score of highscores ScoreHead scores; scores.size = 0; scores.first = NULL; ScoreNode * currScore = NULL; readScores(&scores); currScore = scores.first; int numScores = 1; int highestScore = 0; while ((currScore->next != NULL) && (numScores < 9)) { numScores += 1; currScore = currScore->next; } highestScore = -1; if (numScores > 8 && currScore != NULL) { highestScore = currScore->score; } char * enterName; if (theScore > highestScore) { enterName = drawScore(theScore,1); if (enterName != NULL) { addScore(&scores, enterName, theScore); writeScores(&scores); } } else { drawScore(theScore,0); } if (scores.size > 0) destroyScores(&scores); }