From ff8237ada62924cb26068b1c9c86af5b61a6c367 Mon Sep 17 00:00:00 2001 From: "Alexandru Ivascu (ivascua)" Date: Sat, 8 Feb 2020 14:09:58 +0000 Subject: [PATCH] Only saving works And when saving, it only saves the player's (x,y) coordinates, health, attack and xp; it does not save the map. Save by pressing P. --- Roguelike.cpp | 10 ++++++++-- saveAndLoad.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 saveAndLoad.h diff --git a/Roguelike.cpp b/Roguelike.cpp index 116c1e2..4082aa4 100644 --- a/Roguelike.cpp +++ b/Roguelike.cpp @@ -1,7 +1,7 @@ #include #include "Character.h" #include "Windows.h" -#include "saveAndLoad.cpp" +#include "saveAndLoad.h" using namespace std; @@ -40,6 +40,7 @@ int main() if (goblin.health < 0){ cout<<"You killed him lmao"; map[goblin.x][goblin.y]=' '; + character.xp+=10; } } if (((character.x==goblin.x-1) && (character.y==goblin.y)) || ((character.x==goblin.x+1) && (character.y==goblin.y)) || ((character.x==goblin.x) && (character.y==goblin.y+1)) || ((character.x==goblin.x) && (character.y==goblin.y-1))){ @@ -50,7 +51,12 @@ int main() } if (GetAsyncKeyState(0x50)) //0x50 is the virtual key code for the p key, checks if P has been pressed { //Hopefully creates a .txt file - //saveGame(); + int playerx=character.x; + int playery=character.y; + int playerhealth=character.health; + int playerattack=character.attack; + int playerxp=character.xp; + saveGame(playerx,playery,playerhealth,playerattack,playerxp); } if (GetAsyncKeyState(0x4C)) diff --git a/saveAndLoad.h b/saveAndLoad.h new file mode 100644 index 0000000..7dae1a5 --- /dev/null +++ b/saveAndLoad.h @@ -0,0 +1,17 @@ +#include +#include +using namespace std; + +void saveGame(int x, int y, int health, int attack, int xp){ + ofstream f("latestSaveFile.txt"); + f << x; + f << "."; + f << y; + f << "."; + f << health; + f << "."; + f << attack; + f << "."; + f << xp; + f.close(); +}