Save and load function in Console

Need help to add a save and load function into my Console game in C++

Page 1 of 1

10 Replies - 4414 Views - Last Post: 28 July 2008 - 01:06 PM Rate Topic: -----

#1 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Save and load function in Console

Post icon  Posted 24 July 2008 - 12:31 PM

Hello!

i do a RPG game in C++ Console. But i im a beginner in C++.
It would be nice to you if you could write a code and a descrition to make a save and load function...

I have check on Google and i didn't find anythin :blink: So i wonder if it go to add a save and load function.


Please help! :rolleyes: ;) B) :D
Sorry for my english :pirate:

Is This A Good Question/Topic? 0
  • +

Replies To: Save and load function in Console

#2 joske  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 297
  • Joined: 04-September 07

Re: Save and load function in Console

Posted 24 July 2008 - 12:40 PM

You can start studying how to read and write a file:
http://www.cplusplus...rial/files.html
Was This Post Helpful? 1
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: Save and load function in Console

Posted 24 July 2008 - 12:41 PM

Please don't double post.

I deleted your other thread :)
Was This Post Helpful? 0
  • +
  • -

#4 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Re: Save and load function in Console

Posted 24 July 2008 - 04:02 PM

View Postjoske, on 24 Jul, 2008 - 12:40 PM, said:

You can start studying how to read and write a file:
http://www.cplusplus...rial/files.html



Thanks for your quick answer! :D But it isn't what i looking for.. :ph34r:
But i can use this site, ALOT! :D So thanks for the site, Alot
Was This Post Helpful? 0
  • +
  • -

#5 joske  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 297
  • Joined: 04-September 07

Re: Save and load function in Console

Posted 25 July 2008 - 12:54 AM

so, what are you looking for?
Was This Post Helpful? 0
  • +
  • -

#6 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Re: Save and load function in Console

Posted 25 July 2008 - 12:25 PM

View Postjoske, on 25 Jul, 2008 - 12:54 AM, said:

so, what are you looking for?


Im looking for a Save And Load Function to a Console Game..

It's a GAME so no program function like that one you send me :rolleyes:
I've be happy if you know a website, there it is a tutorial or something in that direction..
Was This Post Helpful? 0
  • +
  • -

#7 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Save and load function in Console

Posted 25 July 2008 - 12:46 PM

Well i could write information about where they are in the game to a file, and then check for and open appropriate files to "jump" them to the correct part of the game. I don't understand what you are asking now.
Was This Post Helpful? 0
  • +
  • -

#8 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Re: Save and load function in Console

Posted 26 July 2008 - 12:26 PM

View Postpolymath, on 25 Jul, 2008 - 12:46 PM, said:

Well i could write information about where they are in the game to a file, and then check for and open appropriate files to "jump" them to the correct part of the game. I don't understand what you are asking now.

Yeah. It's that i looking for :D
Here's the code (if you need it?)

//-------------------------------------------------------------------------------------------------------

/* Name: ICO III alpha 0.1
Copyright: W.O.P LTD  All Rights Reserved
Author: Tommie Larsson and Andreas Ekström
Date:
Description: First version of the game ICO III*/

//-------------------------------------------------------------------------------------------------------

#include <string> // Library
#include <windows.h> // Library
#include <iostream> // Library
#include <fstream.h> // Library
#include <conio.h> // Library

//-------------------------------------------------------------------------------------------------------

using namespace std;

//-------------------------------------------------------------------------------------------------------

short int nInput(0);
string sUsername, sPassword;
char CharInput;

//-------------------------------------------------------------------------------------------------------

int main()
{

//-------------------------------------------------------------------------------------------------------

ofstream MyFile("Credits.txt");
MyFile << "Made by: Tommie Larsson and Andreas Ekström.";
MyFile.close();

//-------------------------------------------------------------------------------------------------------

cout << "Once upon a time 3 mighty colussus came and took the light from our world," << endl
<< "3 years later a boy named Will decied to take back the light" << endl
<< "and restore peach to the world. ";
cout << endl;

//-------------------------------------------------------------------------------------------------------

cout << endl
<< "The boy named Will is you! ";
cout << endl;

//-------------------------------------------------------------------------------------------------------

Sleep (10000);

//-------------------------------------------------------------------------------------------------------

cout << endl
<< endl
<< endl
<< endl
<< endl
<< endl

//-------------------------------------------------------------------------------------------------------

<<  "\t IIII	IIIIIII	IIIIII	   IIII  IIII  IIII" << endl
<<  "\t  II	II		 II	II	   II	II	II" << endl
<<  "\t  II   II		 II	  II	  II	II	II" << endl
<<  "\t  II   II		 II	  II	  II	II	II" << endl
<<  "\t  II	II		 II	II	   II	II	II" << endl
<< "\t IIII	IIIIIII	IIIIII	   IIII  IIII  IIII" << endl
<< endl
<< endl
<< endl
<< endl;

//-------------------------------------------------------------------------------------------------------

while (true)
{

//-------------------------------------------------------------------------------------------------------

cout << "Welcome to ICO III" << endl;
cout << endl;
cout << "1. Start ICO III." << endl;
cout << "2. Credits." << endl;
cout << "3. Exit." << endl;
cout << endl
;cout  << "Choice: " << endl;

//-------------------------------------------------------------------------------------------------------

cin >> nInput;
cout << endl;

//-------------------------------------------------------------------------------------------------------

switch (nInput)
{

//-------------------------------------------------------------------------------------------------------


case 1:
cout << "Welcome I'm Lora and I'm going to guide you trough this game. ";
Sleep (2000);
cout << endl;
cout << "You're now in the village you were born in!" << endl;
cout << endl;
cout << "Where do you want to go?" << endl;
cout << endl;
cout << "1.Go To The Wilderness." << endl;
cout << "2.Go To The Forrest." << endl;
cout << "3.Go To The Bazar." << endl;
cout << "4.Exit." << endl;
cout << endl;
cout << "Choice: ";

//-------------------------------------------------------------------------------------------------------

cin >> nInput;
cout << endl;

//-------------------------------------------------------------------------------------------------------

switch (nInput)
{

//-------------------------------------------------------------------------------------------------------

	case 1:
	cout << "Going To The Wilderness." << endl;
	Sleep (1000);
	cout << "This Can Take A moment... It's Pretty far to the Wilderness. " << endl;
	cout << endl;
	Sleep (10000);
	cout << "WARNING! It's really dangeruos in the Wilderness!" << endl;
	Sleep (1000);
	cout << endl;
	cout << "WARNING! You're scared!" << endl;
	cout << endl;
	Sleep (1000);
	cout << "1. Check Scareometer." << endl;
	Sleep (1000);
	cout << "2. Continue." << endl;
	Sleep (1000);
	cout << "3. Exit." << endl;
	Sleep (1000);
	cout << "Choice: " << endl;

	//...................................................................................................

	cin >> nInput;
	cout << endl;

	//...................................................................................................

	switch (nInput)
	{
		//...............................................................................................

		case 1:
		cout << "Scareometer:" << endl;
		cout << endl;
	Sleep (1000);
	cout << "\t _________________________________________ " << endl;
	cout << "\t |||||||||||||||||						 " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << endl;
	continue;

	case 2:
	cout << "Not finished yet!" << endl;
	//Skriv fortsättning här på Wilderness!
	continue;

	case 3:
	return (0);
	break;

	default:
	cout << "Unvalid choice!" << endl;
	cout << "Please choose another one" << endl;
	cout << endl;


	}


 //-------------------------------------------------------------------------------------------------------

	case 2:
	cout << "This part isn't don yet!" << endl;
	cout << endl;
	cout << "Please choose another one:" << endl;
	cout << endl;
	continue;

//-------------------------------------------------------------------------------------------------------

	case 3:
	cout << "Going To The Bazar." << endl;
	Sleep (1000);
	cout << "This Should Not Take So Long, It's Not So Far To The Bazar." << endl;
	Sleep (9000);
	cout << "Hello Will! Im Ezteban, Im A Friend To Lora." << endl;
	cout << endl;
	Sleep (4000);
	cout << "1.Trust Him." << endl;
	Sleep (1000);
	cout << "2.Don't Trust Him." << endl;
	Sleep (1000);
	cout << "3.Walk Away." << endl;
	Sleep (1000);
	cout << "4.Say That You Trust Him, But You Don't, And Ask Lora When You Come Home." << endl;
	Sleep (3000);
	cout << endl;
	cout << "Choice: ";
	//................................................................

	cin >> nInput;
	cout << endl;

	//.................................................................

	switch (nInput)
	{
	//.................................................................

	case 1:
	cout << "\t Trusterness meter on Ezteban: " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << "\t |||||									 " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << "Im not finished yet.." << endl;
	continue;
	//.................................................................

	case 2:
		cout << "\t Trusterness meter on Ezteban: " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << "\t |										 " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	continue;

	//..................................................................

	case 3:
	cout << "Your now walking away from Ezteban. " << endl;
	cout << endl;
	Sleep (2000);
	cout << "\t Trusterness meter on Ezteban: " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << "\t										   " << endl;
	cout << "\t _________________________________________ " << endl;
	break;

	//..................................................................

	case 4:
	cout << "\t Trusterness meter on Ezteban: " << endl;
	cout << "\t _________________________________________ " << endl;
	cout << "\t										   " << endl;
	cout << "\t _________________________________________" << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	break;

	//...................................................................

	default:
	cout << "Unvalid choice!" << endl;
	cout << "Please choose another one" << endl;
	cout << endl;
	break;
	}

	//...................................................................

//-------------------------------------------------------------------------------------------------------

	case 4:
	return (0);
	break;
//-------------------------------------------------------------------------------------------------------

	default:
	cout << "Unvalid choice!" << endl;
	cout << "Please choose another one" << endl;
	cout << endl;
	continue;

//-------------------------------------------------------------------------------------------------------

return 0;
}

//-------------------------------------------------------------------------------------------------------

case 2:
cout << "Look at the directory where you put this program in" << endl; // Creates a text
cout << "and there it should be a txt document called Credits.txt there." << endl; // Creates a text
cout << endl;
break;

//-------------------------------------------------------------------------------------------------------

case 3:
return 0;
break;

//-------------------------------------------------------------------------------------------------------

default:
cout << "Unvalid choice!" << endl;
cout << "Please choose another one:" << endl;
cout << endl;
break;

//-------------------------------------------------------------------------------------------------------

return 0;
}
}
}

//-------------------------------------------------------------------------------------------------------



It's pretty long.. But here it is :rolleyes: ;)
Was This Post Helpful? 0
  • +
  • -

#9 Codegamer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 04-May 08

Re: Save and load function in Console

Posted 27 July 2008 - 01:35 PM

Hej!, det är Tommie ska bara säga några saker som ska kunna fixa koden eftersom datorn laggar.

I bland måste man ändra break; mot continue; på vissa ställen för att få det riktigt eller flytta de här: } eller { på olika ställen, ganska klurigt att flytta { och } sakerna för det är svårt att hitta rätt.
Was This Post Helpful? 0
  • +
  • -

#10 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Re: Save and load function in Console

Posted 27 July 2008 - 01:39 PM

View PostCodegamer, on 27 Jul, 2008 - 01:35 PM, said:

Hej!, det är Tommie ska bara säga några saker som ska kunna fixa koden eftersom datorn laggar.

I bland måste man ändra break; mot continue; på vissa ställen för att få det riktigt eller flytta de här: } eller { på olika ställen, ganska klurigt att flytta { och } sakerna för det är svårt att hitta rätt.


Hehe.. :P Igentligen ska vi snacka på engelska här.
Men jag vet att det går att byta ut break; mot continue; :P

Det är väl inte svårt att hitta?! :crazy: :blink:
Was This Post Helpful? 0
  • +
  • -

#11 Codegamer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 04-May 08

Re: Save and load function in Console

Posted 28 July 2008 - 01:06 PM

View Postdidair, on 27 Jul, 2008 - 01:39 PM, said:

View PostCodegamer, on 27 Jul, 2008 - 01:35 PM, said:

Hej!, det är Tommie ska bara säga några saker som ska kunna fixa koden eftersom datorn laggar.

I bland måste man ändra break; mot continue; på vissa ställen för att få det riktigt eller flytta de här: } eller { på olika ställen, ganska klurigt att flytta { och } sakerna för det är svårt att hitta rätt.


Hehe.. :P Igentligen ska vi snacka på engelska här.
Men jag vet att det går att byta ut break; mot continue; :P

Det är väl inte svårt att hitta?! :crazy: :blink:


Ok!, but it's hard sometimes:P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1