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:
- 82:3211b31e9421
- Parent:
- 78:6a6c93c19ed1
- Child:
- 85:87bc28b151d8
--- a/SavedGames/SavedGames.cpp Mon May 25 15:59:14 2020 +0000 +++ b/SavedGames/SavedGames.cpp Mon May 25 18:39:51 2020 +0000 @@ -8,20 +8,20 @@ } -bool SavedGames::save_test(Direction d_,SDFileSystem &sd, N5110 &lcd){ +bool SavedGames::save_test(Direction d_,SDFileSystem &sd, N5110 &lcd) { // Objects reqired for test printf("Data save = %d : ",d_); - //Define input data object and set values + // Define input data object and set values SavedGamesData input_data; input_data.score = 0; input_data.lives = 3; input_data.smart_bombs = 4; input_data.alien_number = 5; - //change the save file + // Change the save file saved_games_scroll(d_); add_saved_data(sd, input_data, lcd); @@ -44,7 +44,7 @@ } } -void SavedGames::run_save_test(SDFileSystem &sd, N5110 &lcd){ +void SavedGames::run_save_test(SDFileSystem &sd, N5110 &lcd) { printf ("\nTesting save_test() \n\n"); int passed_counter = 0; @@ -59,19 +59,19 @@ if (save_test(W, sd, lcd)) passed_counter++; if (save_test(NW, sd, lcd)) passed_counter++; - // prints results + // Prints results printf ("\n save_test passed %d tests out of 9\n\n\n", passed_counter); } -void SavedGames::init(){ +void SavedGames::init() { error_ = false; display_data_number_ = 1; } -void SavedGames::check_sd_present(SDFileSystem &sd, N5110 &lcd){ +void SavedGames::check_sd_present(SDFileSystem &sd, N5110 &lcd) { if(!sd.card_present()) { - //print error screen + // Print error screen lcd.clear(); lcd.printString("SD card not ",9,3); lcd.printString(" present ",9,4); @@ -80,10 +80,10 @@ } } -void SavedGames::error_open_file(N5110 &lcd){ +void SavedGames::error_open_file(N5110 &lcd) { error_ = true; - //print error screen + // Print error screen lcd.clear(); lcd.printString(" Unable to ",9,3); lcd.printString(" open file ",9,4); @@ -91,10 +91,10 @@ wait(3); } -void SavedGames::no_saved_files(N5110 &lcd){ +void SavedGames::no_saved_files(N5110 &lcd) { error_ = true; - //print error screen + // Print error screen lcd.clear(); lcd.printString("No saved Files",0,3); lcd.refresh(); @@ -102,15 +102,15 @@ } void SavedGames::add_saved_data(SDFileSystem &sd,SavedGamesData data, - N5110 &lcd){ + N5110 &lcd) { check_sd_present(sd,lcd); FILE *fp; - //overwiretes selected save file - if (display_data_number_ == 1){ + // Overwiretes selected save file + if (display_data_number_ == 1) { fp = fopen("/sd/SavedGamesOne.csv", "w"); // printf ("save1 \n"); - }else if (display_data_number_ == 2){ + }else if (display_data_number_ == 2) { fp = fopen("/sd/SavedGamesTwo.csv", "w"); // printf ("save2\n" ); }else{ @@ -122,29 +122,29 @@ error_open_file(lcd); }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 + // Adda data to file if no error fprintf(fp, "%d,%d,%d,%d\n", data.score, data.lives, data.smart_bombs, data.alien_number); fclose(fp); } } -SavedGamesData SavedGames::read_saved_data(SDFileSystem &sd, N5110 &lcd){ +SavedGamesData SavedGames::read_saved_data(SDFileSystem &sd, N5110 &lcd) { check_sd_present(sd,lcd); FILE *fp; SavedGamesData data; - //opens diplayed file - if (display_data_number_ == 1){ + // Opens diplayed file + if (display_data_number_ == 1) { fp = fopen("/sd/SavedGamesOne.csv", "r"); //printf ("open save1\n"); - }else if (display_data_number_ == 2){ + }else if (display_data_number_ == 2) { fp = fopen("/sd/SavedGamesTwo.csv", "r"); //printf ("open save2\n"); }else{ @@ -152,33 +152,33 @@ // printf ("open save2\n"); } - //check if any saved game files + // Check if any saved game files if (fp == NULL) { no_saved_files(lcd); - //Reads saved data into object + // Reads saved data into object }else{ - //read save file and add values to data objecy + // Read save file and add values to data objecy fscanf(fp, "%d,%d,%d,%d",&data.score, &data.lives,&data.smart_bombs, &data.alien_number); - //printf ("saved_data_vector_ 1%d \n", saved_data_vector.size()); + // printf ("saved_data_vector_ 1%d \n", saved_data_vector.size()); fclose(fp); } return data; } -void SavedGames::display_saved_games(N5110 &lcd){ +void SavedGames::display_saved_games(N5110 &lcd) { lcd.clear(); - //prints saved game screen + // Prints saved game screen lcd.printString("Saved Games",9,0); lcd.drawSprite(39, 18, 3, 5, (int *)arrow_up); lcd.drawSprite(39, 34, 3, 5, (int *)arrow_down); - //prints saved game that is displayed + // Prints saved game that is displayed char buffer[9]; sprintf(buffer,"Save %2d",display_data_number_); lcd.printString(buffer,21,3); @@ -187,15 +187,15 @@ lcd.refresh(); } -void SavedGames::save_game_screen(N5110 &lcd){ +void SavedGames::save_game_screen(N5110 &lcd) { lcd.clear(); - //prints saved game screen + // Prints saved game screen lcd.printString("Select a save",3,0); lcd.drawSprite(39, 18, 3, 5, (int *)arrow_up); lcd.drawSprite(39, 34, 3, 5, (int *)arrow_down); - //prints saved game that is displayed + // Prints saved game that is displayed char buffer[9]; sprintf(buffer,"Save %2d",display_data_number_); lcd.printString(buffer,21,3); @@ -210,13 +210,13 @@ if (d_ == N || d_ == NE || d_ == NW ) { display_data_number_++; - //loops back round when at end of saved game vecotr - if(display_data_number_ > 3){ + // Loops back round when at end of saved game vecotr + if(display_data_number_ > 3) { display_data_number_ = 1; } } else if (d_ == S || d_ == SW || d_ == SE) { display_data_number_--; - if(display_data_number_ < 1 ){ + if(display_data_number_ < 1 ) { display_data_number_ = 3; } } @@ -224,6 +224,6 @@ } -int SavedGames::get_display_data_number(){ +int SavedGames::get_display_data_number() { return display_data_number_; } \ No newline at end of file