Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Revision:
11:7c1e2a9303d3
Parent:
2:532b0225519f
Child:
12:20ac766b3175
diff -r e221bd1ce3ec -r 7c1e2a9303d3 classes/HighScore.cpp
--- a/classes/HighScore.cpp	Tue Apr 20 15:35:00 2021 +0000
+++ b/classes/HighScore.cpp	Wed Apr 21 11:08:02 2021 +0000
@@ -1,1 +1,37 @@
 #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;
+}
\ No newline at end of file