Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi, I want to make a hangman game where the player creates their own levels with their own words. When they are finished they can create some sort of game file that saves their game. That way they can give the file to their friends and they can load it on their computer(they will need a copy of the game itself to run the file).

Other then that these are my questions,

1. how do you make a save game file?

2. how do I load these files to my game and run it?


Thanks in advance.
Posted
Comments
[no name] 11-Jul-12 15:04pm    
This is the kind of question that make you think it's a trick.
A "save game" file is a file just like any other. You open a file for writing, write information to it and then close the file...
You load the file the same way as any other file. You open the file for reading, read the information and then close the file. You use the information in the file you do not "run" it.
Am I missing something in your question?
Sergey Alexandrovich Kryukov 11-Jul-12 17:36pm    
Ha! Best answer so far!
--SA
MR. AngelMendez 12-Jul-12 8:16am    
Thanks, I never knew that. I'm going to take a look at everyone's comments/solutions and see if I can blend it in with my desired result. If I have any questions I'll post it up. Thanks again everyone for your help.

:laugh:

That's a harder question to answer than you think... :D

The reason it's hard to answer is that save games (or any file data for that matter) are not all the same. Some are straight text, others are XML, some are binary, others are databases, yet others are completely proprietary formats that use bits of each of these! So it's hard to say "Here is the code, it saves your game" because it really depends on what you feel is important in a save game file: do you want it readable by anyone who cares to open it in Notepad? Or do you want it encrypted so that it is hard for hackers to play with your game? Both types (and everything inbetween) have been used for save games.

The simplest way to save a hangman game is probably as a straight text file with two lines of text:
MATCHWORD
GUESSESOFAR
So if I was playing with the word "CROSSFIRE" and I had guessed 'A', 'R', 'S' and 'P' your save file would be:
CROSSFIRE
ARSP
To generate the file is easy:
C#
string matchWord = "CROSSFIRE";
string triedLetters = "ARSP";
File.WriteAllText(@"D:\Temp\mySaveFile.SAV", string.Format("{0}\n{1}", matchWord, triedLetters));
To read it back is pretty easy too:
C#
string[] lines = File.ReadAllLines(@"D:\Temp\mySaveFile.SAV");
if (lines.Length == 2)
   {
   matchWord = lines[0];
   foreach (char c in lines[1])
      {
      Guess(c);
      }
   }


[edit]I forgot a close bracket :O - OriginalGriff[/edit]
 
Share this answer
 
v2
This is a very broad question, but I'll try to point you in the right direction:

1) Figure out what values need to be saved. If it can be generated in code don't worry about it (e.g. if you want to save information about a rectangle, you don't need to save all three of height, width, and area, because any one of those can be determined from the other two)
2) Decide a format. The easiest thing to do is to make a text file, one value on each line, or comma/tab/etc. separated. The format used by INI files is also fairly simple, and easy to manually read to check for errors. Since you tagged this C#, XML is also a good choice (check out LINQ to XML[^]).
3) Write the file. Creating files is well documented online, do a quick Google search if you don't know how.

Loading is just reading in the values (translating/parsing as necessary) and assigning them to the proper places.
 
Share this answer
 
Hi,

didn't had to think about this case yet, I'm not a game developer.
But you surly have to save all settings/states like which level you are reached and maybe in which section of the level, the health of your player, maybe items you've earned, in short form: all things which are different to your starting point.
I would use a BinaryReader/Writer to save it as a .DAT file or something to store/load information.

Good Luck, it shouldn't be to hard to achieve it ;)

Best Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900