Thread: Sequential file question

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    Sequential file question

    Currently in the final three weeks of this semester and stressed to a level that is unheard of right now. The final piece is to make a game all in C++, I have an idea and I am trying to figure out how to do it.

    I want to make a map whether randomly or actually coming up with the layout and have it save to a txt file. For example I want to make a 5x5 map have it print out on the screen, and be saved in the txt file. Then be able to recall that map whenever I want. Such as a town map. My question is, how do you create a map in the txt file(in notepad) from scratch, then with the program call that map up, save any progress made on it. Then when you load the game later start from that point and everything there be saved? I understand the writing, and reading parts of fstream but I am not sure how to write something in notepad and have it created.

    Also I am trying to figure this out for character stats. I have looked around but have not found any tutorials in how to do this as a guideline in how to do it.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    One way would be to save on a basis of 2D (or 3D) points. Certain sets of points could refer to a line, or polyline, or an arc or curve, or meshes of filled triangles. This is how DXF files are saved if you have ever worked with any CAD type packages.

    Or, you could have a point and vector combination.

    A point can easily be saved as (x,y) or (x,y,z) in text format. Vectors can be represented via [x,y,z] format.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    6
    I'm only doing 2 dimensional arrays for the maps. I'm not touching upon 3d stuff yet.

    Overall idea for this is just a 'game' that is like an old monster rancher game. Except that you can move around on the maps. The theory is that it is very simple. The problem I have is the txt file.

    Like I want to have for example stats such as:

    Name:
    race:
    HP:
    MP:
    XP:

    That type format for the monsters, and it all be stored in the txt file. Would I be able to have it say something like Monster 1 and using a for loop I can build the monster list by calling up the stats and it would then print the stats I listed above with the name, race and stats Like this:

    Monster 1
    Name: White Dragon
    Race: Dragon
    HP: 100
    MP: 50
    XP: 20

    Just call up Monster 1 or the name of the monster from the txt file and print it up using the cout

    I'm just trying to figure out If you write all the information you want in the txt file exactly how you want for the stats if it would print out those stats. (this probably is the easiest part is stats)

    The map however to me poses the bigger problem, How do you "write" the map in the txt file and then pull it up on screen, or generate it in the program save it in the txt file and go on from there.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The way you ask that question "How do you "write" the map in the txt file" suggests you believe there is an answer. You write the map in the txt file however you want to do it. How are you storing the map, and what is it going to be easy for you to write out and what will you need in order to be able to easily reconstruct the map as it gets read in? Whatever that is, that's what you put in the file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about file streams.
    By Lawn Gnomusrex in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2008, 06:05 AM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. fputs and sequential file
    By sballew in forum C Programming
    Replies: 5
    Last Post: 11-11-2001, 04:48 PM