You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Save.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "..\C-Engine\CHeader.hpp"
  2. #include "Save.hpp"
  3. extern "C"
  4. {
  5. #include "Memory/memory.h"
  6. }
  7. Save::Save()
  8. {
  9. nblevel = 3;
  10. UserInfo = NULL;
  11. TabLevel = NULL;
  12. data = NULL;
  13. lenght = 0;
  14. }
  15. Save::~Save()
  16. {
  17. delete data;
  18. delete UserInfo;
  19. for(int i = 0 ; i < nblevel ; i++)
  20. {
  21. delete TabLevel[i];
  22. }
  23. delete TabLevel;
  24. }
  25. void Save::LoadData()
  26. {
  27. UserInfo = new Info;
  28. TabLevel = new Level*[nblevel];
  29. for(int i = 0 ; i < nblevel ; i++)
  30. {
  31. TabLevel[i] = new Level;
  32. }
  33. if(memory_exists("\\\\fls0\\Dash.sav"))
  34. {
  35. data = (int*)memory_load("\\\\fls0\\Dash.sav");
  36. UserInfo->nbattemp = data[0];
  37. UserInfo->nbjump = data[1];
  38. UserInfo->nbtime = data[2];
  39. UserInfo->completlevel = data[3];
  40. UserInfo->perso = data[4];
  41. UserInfo->mini = data[5];
  42. for(int i = 0 ; i < nblevel ; i++)
  43. {
  44. TabLevel[i]->normalprogress = data[6 + i * 2];
  45. TabLevel[i]->practiseprogress = data[7 + i * 2];
  46. }
  47. free(data);
  48. }
  49. else
  50. {
  51. UserInfo->nbattemp = 0;
  52. UserInfo->nbjump = 0;
  53. UserInfo->nbtime = 0;
  54. UserInfo->completlevel = 0;
  55. UserInfo->perso = 0;
  56. UserInfo->mini = 0;
  57. for(int i = 0 ; i < nblevel ; i++)
  58. {
  59. TabLevel[i]->normalprogress = 0;
  60. TabLevel[i]->practiseprogress = 0;
  61. }
  62. }
  63. }
  64. void Save::SaveData()
  65. {
  66. //Encapssulation des données.
  67. lenght = 6 + nblevel * 2;
  68. data = new int[lenght];
  69. data[0] = UserInfo->nbattemp;
  70. data[1] = UserInfo->nbjump;
  71. data[2] = UserInfo->nbtime;
  72. data[3] = UserInfo->completlevel;
  73. data[4] = UserInfo->perso;
  74. data[5] = UserInfo->mini;
  75. for(int i = 0 ; i < nblevel ; i++)
  76. {
  77. data[6 + i * 2] = TabLevel[i]->normalprogress;
  78. data[7 + i * 2] = TabLevel[i]->practiseprogress;
  79. }
  80. //fin de l'encapssulation.
  81. int error = memory_save("\\\\fls0\\Dash.sav",data,lenght * sizeof (int)); //Sauvegarde
  82. delete data;
  83. }