Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

classes/HighScore.cpp

Committer:
el18a2k
Date:
2021-04-21
Revision:
11:7c1e2a9303d3
Parent:
2:532b0225519f
Child:
12:20ac766b3175

File content as of revision 11:7c1e2a9303d3:

#include "HighScore.h"

LocalFileSystem local("scores"); //define local file system

//display value in file
void HighScore::display_File(N5110 &lcd){
    FILE* Scores = fopen("/scores/textfile.txt","r"); //opens and reads file
    fgets(readScore1, 8, Scores); //read first data value and stores it in string 'readScore'
    fclose(Scores); //closes Scores    
        
    lcd.clear();
    lcd.printString(" 1st. ", 5, 1);
    lcd.printString(readScore1, 40, 1);
    lcd.refresh();
}
    
//amend file
void HighScore::write_File(int score){
    score1 = score;
                                //string            int
    stringCon1 = sprintf(writeScore1, "%i", score1); //converts int into string   
    FILE* Scores = fopen("/scores/textfile.txt","w"); //create a pointer called scores which opens a textfile and writes
    fputs(writeScore1, Scores); //writes string writeScore1 to file
    fclose(Scores);
}

//read from file
int HighScore::read_File(){
    FILE* Scores = fopen("/scores/textfile.txt","r"); //opens and reads file
    fgets(readScore1, 8, Scores); //read first data value and stores it in string 'readScore'
    fclose(Scores); //closes Scores 
    
    //converts string back to int
    readScore = atoi(readScore1);
    
    return readScore;
}