Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: SavedGames/SavedGames.cpp
- Revision:
- 63:4631447440cf
- Parent:
- 62:f0c86a854a9e
- Child:
- 64:e9dfc35a1738
diff -r f0c86a854a9e -r 4631447440cf SavedGames/SavedGames.cpp
--- a/SavedGames/SavedGames.cpp Wed May 20 21:15:50 2020 +0000
+++ b/SavedGames/SavedGames.cpp Thu May 21 00:09:10 2020 +0000
@@ -24,12 +24,11 @@
error_ = false;
check_sd_present(sd,lcd);
display_data_number_ = 1;
+
}
-void SavedGames::check_sd_present(SDFileSystem &sd,N5110 &lcd){
- if(!sd.card_present()) {
- error_ = true;
-
+void SavedGames::check_sd_present(SDFileSystem &sd, N5110 &lcd){
+ if(sd.card_present()) {
//print error screen
lcd.clear();
lcd.printString("SD card not ",9,3);
@@ -41,7 +40,7 @@
void SavedGames::error_open_file(N5110 &lcd){
error_ = true;
-
+
//print error screen
lcd.clear();
lcd.printString(" Unable to ",9,3);
@@ -52,7 +51,7 @@
void SavedGames::no_saved_files(N5110 &lcd){
error_ = true;
-
+
//print error screen
lcd.clear();
lcd.printString("No saved Files",0,3);
@@ -67,23 +66,23 @@
//opens correct save file
if (display_data_number_ == 1){
fp = fopen("/sd/SavedGamesOne.csv", "w");
- printf ("save1 \n");
+ // printf ("save1 \n");
}else if (display_data_number_ == 2){
fp = fopen("/sd/SavedGamesTwo.csv", "w");
- printf ("save2\n" );
+ // printf ("save2\n" );
}else{
fp = fopen("/sd/SavedGamesThree.csv", "w");
- printf ("save2 \n");
+ // printf ("save2 \n");
}
-
+
if (fp == NULL) {
error_open_file(lcd);
- return;
+
}else{
- printf ("add data.score = %d \n", data.score);
- printf ("add data.lives = %d \n", data.lives);
- printf ("adddata.smart_bombs = %d \n", data.smart_bombs);
- printf ("add data.alien_number = %d \n", data.lives);
+ //printf ("add data.score = %d \n", data.score);
+ //printf ("add data.lives = %d \n", data.lives);
+ //printf ("adddata.smart_bombs = %d \n", data.smart_bombs);
+ //printf ("add data.alien_number = %d \n", data.lives);
//Adda data to file if no error
fprintf(fp, "%d,%d,%d,%d\n", data.score, data.lives, data.smart_bombs,
data.alien_number);
@@ -98,19 +97,18 @@
//opens diplayed file
if (display_data_number_ == 1){
fp = fopen("/sd/SavedGamesOne.csv", "r");
- printf ("open save1\n");
+ //printf ("open save1\n");
}else if (display_data_number_ == 2){
- fp = fopen("/sd/SavedGamesTwo.csv", "r");
+ //fp = fopen("/sd/SavedGamesTwo.csv", "r");
printf ("open save2\n");
}else{
fp = fopen("/sd/SavedGamesThree.csv", "r");
- printf ("open save2\n");
+ // printf ("open save2\n");
}
if (fp == NULL) {
- no_saved_files(lcd);
-
- //Reads saved data into vector
+ no_saved_files(lcd);
+ //Reads saved data into object
}else{
int lives;
int score;
@@ -122,16 +120,18 @@
//sets data to object
data.score = score;
- printf ("data.score = %d \n", data.score);
+ // printf ("data.score = %d \n", data.score);
data.lives = lives;
- printf ("data.lives = %d \n", data.lives);
+ // printf ("data.lives = %d \n", data.lives);
data.smart_bombs = smart_bombs;
- printf ("data.smart_bombs = %d \n", data.smart_bombs);
+ //printf ("data.smart_bombs = %d \n", data.smart_bombs);
data.alien_number = alien_number;
- printf ("data.alien_number = %d \n", data.lives);
+ //printf ("data.alien_number = %d \n", data.lives);
+
+ //printf ("saved_data_vector_ 1%d \n", saved_data_vector.size());
+ fclose(fp);
}
- //printf ("saved_data_vector_ 1%d \n", saved_data_vector.size());
- fclose(fp);
+
return data;
}
@@ -171,6 +171,12 @@
return error_;
}
+
+bool SavedGames::set_error(bool error){
+ error_ = error;
+}
+
+
int SavedGames::get_display_data_number(){
return display_data_number_;
}