James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Revision:
26:0dc10374546f
Parent:
25:b52aa23df120
Child:
35:138ad0faa42b
--- a/Options_Engine/OptionsEngine.cpp	Sun Apr 21 13:20:12 2019 +0000
+++ b/Options_Engine/OptionsEngine.cpp	Tue Apr 23 23:55:05 2019 +0000
@@ -1,5 +1,10 @@
 #include "OptionsEngine.h"
 
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <functional>
+
 OptionsEngine::OptionsEngine(){
 }
 
@@ -9,7 +14,7 @@
 void OptionsEngine::init(){
     _state = BRIGHTNESS;
     _brightness = 0.5;
-    _ball_speed = 0.5;   
+    _ball_speed = 5;   
 }
 
 void OptionsEngine::display_options(N5110 &lcd){
@@ -85,19 +90,33 @@
     if(_ball_speed > 10){ _ball_speed = 10; }
 }
 
-void OptionsEngine::view_high_scores(Gamepad &gamepad, N5110 &lcd, SDFileSystem &sd){
+void OptionsEngine::view_high_scores(Gamepad &gamepad, N5110 &lcd){
     _leaderboard = CLASSIC_MODE; 
     while(!(gamepad.check_event(gamepad.A_PRESSED))){
         if(gamepad.check_event(gamepad.R_PRESSED)){ _leaderboard = BRICKBREAKER_MODE; }
         if(gamepad.check_event(gamepad.L_PRESSED)){ _leaderboard = CLASSIC_MODE; }
         lcd.clear();
-        print_high_scores(lcd, sd);
+        print_high_scores(lcd);
         lcd.refresh();
         wait(0.2);
     }
 }
 
-void OptionsEngine::print_high_scores(N5110 &lcd, SDFileSystem &sd){
+void OptionsEngine::read_bb_high_scores(){
+    std::ifstream file;
+    file.open("/sd/bbhighscores.txt");
+    if(!(file.is_open())){
+        printf("Error: Could not open file");
+    }
+    std::string nth_score;
+    for(int n = 0; n < 5; n++){
+        std::getline(file, nth_score);
+        std::istringstream ipstream(nth_score);
+        ipstream >> _bbarray[n];
+    }
+}
+
+void OptionsEngine::print_high_scores(N5110 &lcd){
     if(_leaderboard == CLASSIC_MODE){
         lcd.printString("Classic", 21, 0);
         lcd.printString("1.", 0, 1);
@@ -109,14 +128,13 @@
         
     }
     if(_leaderboard == BRICKBREAKER_MODE){
+        read_bb_high_scores();
         lcd.printString("Brickbreak", 12, 0);
-        lcd.printString("1.", 0, 1);
-        lcd.printString("2.", 0, 2);
-        lcd.printString("3.", 0, 3); lcd.printString("<L", 72, 3);
-        lcd.printString("4.", 0, 4);
-        lcd.printString("5.", 0, 5);
-        
-        
-        
+        for (int i = 1; i < 6; i++){
+            char buffer[6];
+            sprintf(buffer, "%1d. %2d", i, _bbarray[i-1]);
+            lcd.printString(buffer, 0, i);
+        }
+        lcd.printString("<L", 72, 3);  
     }
 }
\ No newline at end of file