Game Creating Help Again

Started by
21 comments, last by Denisb 14 years, 8 months ago
Quote:Original post by Denisb
Thanks all but. How do i make it load the game :O

This is how you could do it.
This is the struct that will be used to hold the game info for the save and the load functions:

struct status{	string name;	int gold;	int TP; // Time played};


Then I made a function (in my game it's a class function, so you'll have to implement it the way you want) called Game::gSave():

void Game::gSave(){	status game; // class of type status, look up	game.name = hName;	game.gold = gGold;	game.TP = gTP;	ofstream save("game.sav", ios::out | ios::binary);	if (!save)	{		cout << "\nCan't open the file for saving!\n";	}	else	{		save.write((char *) &game, sizeof(status));		cout << "\nGame saved!\n";		save.close();	}}


And here comes the the source for loading the game:

void Game::gLoad(){	status game;	ifstream load("game.sav", ios::in | ios::binary);	if (!load)	{		cout << "\nCan't open the file for loading!\n";	}	else	{		load.read((char *) &game, sizeof(status));		hName = game.name;		gGold = game.gold;		gTP = game.TP;				cout << "\nThe following game stats are loaded:\n";		cout << "Name: " << hName << "\n";		cout << "Gold: " << gGold << "\n";		cout << "Time played: " << gTP << "\n";		load.close();	}}


If you got any questions, just ask :-D
Advertisement
Quote:Original post by ssj4leon
Quote:Original post by Denisb
Thanks all but. How do i make it load the game :O

This is how you could do it.
This is the struct that will be used to hold the game info for the save and the load functions:

*** Source Snippet Removed ***

Then I made a function (in my game it's a class function, so you'll have to implement it the way you want) called Game::gSave():

*** Source Snippet Removed ***

And here comes the the source for loading the game:

*** Source Snippet Removed ***

If you got any questions, just ask :-D


Allright thanks. Going to test it later :)
alright it works. Thanks.

So i go develope some and then im gone for some weeks and then i continue again :)

This topic is closed to new replies.

Advertisement