jordan harper
/
GameProject
Diff: main.cpp
- Revision:
- 19:baa140ab4490
- Parent:
- 18:c93c501ed1c0
- Child:
- 20:ef5e8840cb9a
--- a/main.cpp Thu Apr 30 18:29:35 2015 +0000 +++ b/main.cpp Fri May 01 11:00:47 2015 +0000 @@ -284,9 +284,7 @@ while(1) { if(button == 1) { clearCells(); - lcd.printString("scoring",0,2); //enter function to commence here - wait(3.0); - break; + readDataFromFile(); } else { break; } @@ -437,9 +435,8 @@ j=j; } if (lcd.getPixel(i,j-1)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -501,9 +498,8 @@ } } if (lcd.getPixel(i+1,j-1)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -564,9 +560,8 @@ } } if (lcd.getPixel(i+2,j-1)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -625,9 +620,8 @@ } } if (lcd.getPixel(i,j)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -689,9 +683,8 @@ } } if (lcd.getPixel(i+1,j)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -752,9 +745,8 @@ } } if (lcd.getPixel(i+2,j)) { - readDataFromFile(); + writeDataToFile(); // write current value to disk - clearCells(); int m = 1; lcd.printString("game over",1,2); @@ -1093,23 +1085,23 @@ void writeDataToFile() { - - FILE *fp = fopen("/local/score.csv", "w"); // open 'score.txt' + FILE *fp = fopen("/local/score.txt", "w"); // open 'score.txt' // if the file doesn't exist it is created, if it exists, data is appended to the end - fprintf(fp,"%i",score); // print string to file + fprintf(fp,"%i",score); // print integer to file fclose(fp); // close file } - void readDataFromFile() - { - char Buffer[14]; - - FILE *fp2 = fopen("/local/score.csv", "r"); // open 'score.txt' - fscanf (fp2, "%i",score); - sprintf(Buffer,"%i", score); +void readDataFromFile() +{ + int score1; + + FILE *fp2 = fopen("/local/score.txt", "r"); // open 'score.txt' + fscanf (fp2,"%i",&score1); fclose(fp2); // close file - lcd.printString(Buffer,0,0); - wait(3); + + char Points[14]; + sprintf(Points,"%i",score1); + lcd.printString(Points,0,0); }