ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18gs

Dependencies:   mbed

Revision:
16:3b298bea3a70
Parent:
8:4220d116f17c
--- a/Inventory/Ghost/Ghost.cpp	Wed May 13 10:19:10 2020 +0000
+++ b/Inventory/Ghost/Ghost.cpp	Tue May 26 12:17:52 2020 +0000
@@ -15,7 +15,7 @@
         _names.push_back(names[i]);
     }
     
-    _root = root;
+    _root = "/sd/ghosts/";
 
     // Connections to SD card holder on K64F (SPI interface)
     //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
@@ -76,7 +76,7 @@
     for(int i = 0; i < 20; i++){
         _names.push_back(names[i]);
     }
-    _root = root;
+    _root = "/sd/ghosts/";
     _uid = gen_uid(sd);
     int type = 0;
     if ((num > 0) && (num < 50)) {
@@ -162,8 +162,8 @@
 {
     FILE *fp; // this is our file pointer
 
-    std::string filepath = "/sd";
-
+    std::string filepath = "";
+    printf("%s\n", _root.c_str());
     filepath.append(_root);
 
     char buf[10];
@@ -176,6 +176,8 @@
 
     if (fp == NULL) {  // if it can't open the file then print error message
         printf("Error! Unable to open file!\n");
+        printf(filepath.c_str());
+        printf("\n");
     } else {  // opened file so can write
         fprintf(fp, "/Type\n");
         fprintf(fp, "%s\n", get_type_string().c_str());
@@ -221,6 +223,7 @@
 
 void Ghost::feed(int ammount, SDFileSystem &sd)
 {
+    printf("feeding ghost\n");
     _xp = _xp + ammount;
 
     int new_level = 0;
@@ -259,6 +262,8 @@
         }
     }
 
+    _level = new_level;
+
     save(sd);
 }