some help with fstream

This is a discussion on some help with fstream within the C++ Programming forums, part of the General Programming Boards category; ok i downloaded this code from www.gametutorials.com (i think thats the site, ill double check after this post) which is ...

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116

    some help with fstream

    ok i downloaded this code from www.gametutorials.com (i think thats the site, ill double check after this post) which is a basic code which generates a random maze, and puts green '#' where the walls are. i want to modify it so i can use static mazes, like maybe for an rpg, and so i was thinking i could "draw" it in a .txt file and have the program open it and make the maze based on that. but im not sure how i would go about doing that, and help is greatly appreciated.

    (and note: this is specificy written for dev-cpp, so i included the exe in it in case someone didnt have dev and couldnt compile it. if you dont trust to run an exe from me, go to gametutorials and download it there.)
    Attached Files Attached Files
    Last edited by Geo-Fry; 05-03-2003 at 03:45 PM.
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  2. #2
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    hm, maybe that was a bad question?
    well anyway, i have an idea of what i could try:
    Code:
    ...
    int main()
    {
      fstream map("map.txt", ios::in | ios::out);
    ...
      for(int y = 0; y < buffersize.y; y++)
      {
        for (int x = 0; x < buffersize.x; x++)
        {
          int number = (x * 30) + y; //the map is 30 spaces wide, so in order for each space to have
          //a unique value with only one number, yoou cant just add x and y.
          char currentSpace = map.seekg (number, ios::beginning)
          if (currentSpace == '#')
          {
            screenBuffer[x + y * SCREEN_WIDTH].Char.AsciiChar = WALL;
            screenBuffer[x + y * SCREEN_WIDTH].Attributes = FOREGROUND_GREEN;
          //rest of code as found in attachment in my previous post
    but that doesnt work, i think its the char currentSpace = map.seekg (number, ios::beginning) with what can i replace that?
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 09:19 PM
  2. Fstream. I/O
    By kevinawad in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2008, 09:19 AM
  3. ARGH! fstream errors
    By OttoDestruct in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:37 PM
  4. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 11:21 AM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21