Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Committer:
el18a2k
Date:
Wed Apr 21 15:24:31 2021 +0000
Revision:
12:20ac766b3175
Parent:
11:7c1e2a9303d3
Child:
14:f1552b691274
lots of bugs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18a2k 2:532b0225519f 1 #include "HighScore.h"
el18a2k 11:7c1e2a9303d3 2
el18a2k 11:7c1e2a9303d3 3 LocalFileSystem local("scores"); //define local file system
el18a2k 11:7c1e2a9303d3 4
el18a2k 11:7c1e2a9303d3 5 //display value in file
el18a2k 12:20ac766b3175 6 void HighScore::displayFile(N5110 &lcd){
el18a2k 11:7c1e2a9303d3 7 FILE* Scores = fopen("/scores/textfile.txt","r"); //opens and reads file
el18a2k 11:7c1e2a9303d3 8 fgets(readScore1, 8, Scores); //read first data value and stores it in string 'readScore'
el18a2k 11:7c1e2a9303d3 9 fclose(Scores); //closes Scores
el18a2k 11:7c1e2a9303d3 10
el18a2k 11:7c1e2a9303d3 11 lcd.clear();
el18a2k 12:20ac766b3175 12 lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
el18a2k 12:20ac766b3175 13 lcd.printString(" Top Score", 12, 1);
el18a2k 12:20ac766b3175 14 lcd.printString(readScore1, 30, 3);
el18a2k 11:7c1e2a9303d3 15 lcd.refresh();
el18a2k 11:7c1e2a9303d3 16 }
el18a2k 11:7c1e2a9303d3 17
el18a2k 12:20ac766b3175 18 //write/amend file
el18a2k 12:20ac766b3175 19 void HighScore::writeFile(int score){
el18a2k 11:7c1e2a9303d3 20 score1 = score;
el18a2k 11:7c1e2a9303d3 21 //string int
el18a2k 11:7c1e2a9303d3 22 stringCon1 = sprintf(writeScore1, "%i", score1); //converts int into string
el18a2k 11:7c1e2a9303d3 23 FILE* Scores = fopen("/scores/textfile.txt","w"); //create a pointer called scores which opens a textfile and writes
el18a2k 11:7c1e2a9303d3 24 fputs(writeScore1, Scores); //writes string writeScore1 to file
el18a2k 11:7c1e2a9303d3 25 fclose(Scores);
el18a2k 11:7c1e2a9303d3 26 }
el18a2k 11:7c1e2a9303d3 27
el18a2k 11:7c1e2a9303d3 28 //read from file
el18a2k 12:20ac766b3175 29 int HighScore::readFile(){
el18a2k 11:7c1e2a9303d3 30 FILE* Scores = fopen("/scores/textfile.txt","r"); //opens and reads file
el18a2k 11:7c1e2a9303d3 31 fgets(readScore1, 8, Scores); //read first data value and stores it in string 'readScore'
el18a2k 11:7c1e2a9303d3 32 fclose(Scores); //closes Scores
el18a2k 11:7c1e2a9303d3 33
el18a2k 11:7c1e2a9303d3 34 //converts string back to int
el18a2k 11:7c1e2a9303d3 35 readScore = atoi(readScore1);
el18a2k 11:7c1e2a9303d3 36
el18a2k 11:7c1e2a9303d3 37 return readScore;
el18a2k 11:7c1e2a9303d3 38 }