Help - Search - Members - Calendar
Full Version: The trials and tribulations of making a game:
Ambrosia Software Web Board > General Interest > Just Games
theGlueBubble
CODE
void saveRoom()
    {
/*


13  items
14    monsters
15    <value> door name
16    hasBeenExplored?
17  hasBeenSearched?
18  hasMonsterPresent?

*/
    int index;
    int x = -1000, y = -1000, z = -1000;
    apstring dummy;
    
    fstream ioFile;
    
    apstring fileName = "Data";
    
    ioFile.open(fileName.c_str(), ios: :out | ios::in);
    
    if (ioFile.fail())
 {
 cout << "ioFile failed." << endl;
 ofstream outFile;
 outFile.open("Data");
 outFile << "****ing well work!" << endl;
 outFile.close;
 
 ioFile.open(fileName.c_str(), ios: :out | ios::in);
 }
    
    
    while ((!ioFile.fail()) && (!ioFile.eof()) && ((coordX != x) || (coordY != y) || (coordZ != z)))
 {
 cout << "enter while loop" << endl;
 ioFile >> index;
 //cout << "index:  " << index << endl;
 
 if (index == 1)
     {
     ioFile >> x >> y >> z;
     
     getline (ioFile, dummy);
     //cout << "X: " << coordX << "  Y: " << coordY << "  Z: " << coordZ << endl;
     //cout << dummy << endl;
     }
     
 else
     {
     getline (ioFile, dummy);
     //cout << dummy << "else" << endl;
     }
 //cin.get();
 }
    
    
    if (!ioFile.eof() && !ioFile.fail())
 {
 cout << "enter if the file exists and we're not at the end of it" << endl;
 // room description
 ioFile >> index;
 ioFile.get();
 ioFile << description;
 for (int z = 0; z < 255 - description.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // search description
 ioFile >> index;
 ioFile.get();
 ioFile << searchMsg;
 for (int z = 0; z < 255 - searchMsg.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 // error to the north
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[north];
 for (int z = 0; z < 255 - errorMsg[north].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
    
 
 
 // error to the south
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[south];
 for (int z = 0; z < 255 - errorMsg[south].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // error to the east
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[east];
 for (int z = 0; z < 255 - errorMsg[east].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 
 // error to the west
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[west];
 for (int z = 0; z < 255 - errorMsg[west].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // error down
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[down];
 for (int z = 0; z < 255 - errorMsg[down].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // error up
 ioFile >> index;
 ioFile.get();
 ioFile << errorMsg[up];
 for (int z = 0; z < 255 - errorMsg[up].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 
 // room graphic title (on enter)
 ioFile >> index;
 ioFile.get();
 ioFile << onEnterRoom;
 for (int z = 0; z < 30 - onEnterRoom.length(); z++)    
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // onMonstersDeath graphic title
 ioFile >> index;
 ioFile.get();
 ioFile << onMonstersDeath;
 for (int z = 0; z < 30 - onMonstersDeath.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
 
 // search graphic title
 ioFile >> index;
 ioFile.get();
 ioFile << onExamineRoom;
 for (int z = 0; z < 30 - onExamineRoom.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 
     
 
    
 // item saving
 int counter = 0;
    
 while (counter < MAX_NUM)
     {
     ioFile >> index;
     ioFile.get();
     ioFile << itemName[counter];
     for (int z = 0; z < 30 - itemName[counter].length(); z++)
   {
   ioFile << "ø";
   }
     ioFile.get();
     }
    
    
 // monster saving
 counter = 0;
    
 while (counter < MAX_NUM)
     {
     ioFile >> index;
     ioFile.get();
     ioFile << monsterName[counter];
     for (int z = 0; z < 30 - monsterName[counter].length(); z++)
   {
   ioFile << "ø";
   }
     ioFile.get();
     }
 
    
 // door saving
 ioFile >> index;
 ioFile.get();
 ioFile << doorKey << " " << door;
 for (int z = 0; z < 30 - door.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile.get();
 
 /*
 // hasBeenExplored
 ioFile >> index;
 ioFile.get();
 ioFile << rooms.aRoom.explored[a][b][c];
 ioFile.get();
 
 // has been searched
 ioFile >> index;
 ioFile.get();
 ioFile << rooms.aRoom.searched[a][b][c];
 ioFile.get();
 
 
 //monstersPresent?  <-- dunno why I need to do this, maybe I don't remember the code
 // that sets the variable..thought it just checked to see if there was a monster, and
 // an if regulated the map output later
 ioFile >> index;
 ioFile.get();
 ioFile << rooms.aRoom.monsterPresent[a][b][c];
 ioFile.get();*/
 
 
 }// end if !eof
 
    else
 {
 cout << "entered else statement." << endl;
 ioFile << ios::app;
 // output room coords
 
 ioFile << 1 << " ";
 ioFile << x << " " << y << " " << z << " " << endl;
 cout << "end room coords." << endl;
 
 
 
 
 
   
 // room description
 ioFile << 2;
 ioFile << " ";
 ioFile << description;
 for (int z = 0; z < 255 - description.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end room description" << endl;
 
 
 
 // search description
 ioFile << 3;
 ioFile << " ";
 ioFile << searchMsg;
 for (int z = 0; z < 255 - searchMsg.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end search description" << endl;
 
 
 // error to the north
 ioFile << 4;
 ioFile << " ";
 ioFile << errorMsg[north];
 for (int z = 0; z < 255 - errorMsg[north].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 
 cout << "end error north" << endl;
    
 
 
 // error to the south
 ioFile << 5;
 ioFile << " ";
 ioFile << errorMsg[south];
 for (int z = 0; z < 255 - errorMsg[south].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end error south." << endl;
 
 
 
 // error to the east
 ioFile << 6;
 ioFile << " ";
 ioFile << errorMsg[east];
 for (int z = 0; z < 255 - errorMsg[east].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end error east" << endl;
 
 
 
 
 // error to the west
 ioFile << 7;
 ioFile << " ";
 ioFile << errorMsg[west];
 for (int z = 0; z < 255 - errorMsg[west].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end error west" << endl;
 
 
 
 // error down
 ioFile << 8;
 ioFile << " ";
 ioFile << errorMsg[down];
 for (int z = 0; z < 255 - errorMsg[down].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end error down" << endl;
 
 
 
 // error up
 ioFile << 9;
 ioFile << " ";
 ioFile << errorMsg[up];
 for (int z = 0; z < 255 - errorMsg[up].length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end error up" << endl;
 
 
 
 
 // room graphic title (on enter)
 ioFile << 10;
 ioFile << " ";
 ioFile << onEnterRoom;
 for (int z = 0; z < 30 - onEnterRoom.length(); z++)    
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end enter room" << endl;
 
 
 
 // onMonstersDeath graphic title
 ioFile << 11;
 ioFile << " ";
 ioFile << onMonstersDeath;
 for (int z = 0; z < 30 - onMonstersDeath.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end on monster death" << endl;
 
 
 
 // search graphic title
 ioFile << 12;
 ioFile << " ";
 ioFile << onExamineRoom;
 for (int z = 0; z < 30 - onExamineRoom.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end examine room" << endl;
 
 
     
 
    
 // item saving
 int counter = 0;
    
 while (counter < MAX_NUM)
     {
     ioFile << 13;
     ioFile << " ";
     ioFile << itemName[counter];
     for (int z = 0; z < 30 - itemName[counter].length(); z++)
   {
   ioFile << "ø";
   }
     ioFile << endl;
     counter++;
     }
 cout << "end item saving" << endl;
    
    
 // monster saving
 counter = 0;
    
 while (counter < MAX_NUM)
     {
     ioFile << 14;
     ioFile << " ";
     ioFile << monsterName[counter];
     for (int z = 0; z < 30 - monsterName[counter].length(); z++)
   {
   ioFile << "ø";
   }
     ioFile << endl;
     counter++;
     }
 cout << "end monster saving" << endl;
    
 // door saving
 ioFile << 15;
 ioFile << " ";
 ioFile << doorKey << " " << door;
 for (int z = 0; z < 30 - door.length(); z++)
     {
     ioFile << "ø";
     }
 ioFile << endl;
 cout << "end door" << endl;
 
/////////////////////////////////////////////////////
////////////////////////////////////////////////////////    
    
 } // end else


If only that would work...

I've spent the past few hours on that, and related, FoDN (see sig) code. Gods, but I wish my original design would have worked. For some damned reason, ioFile won't output to the file. ****ing A.

------------------
Fortress of Die Nacht: An upcoming game from Aviary Productions.
Go take a look! | FoDN Progress Log

[This message has been edited by theGlueBubble (edited 11-05-2001).]
theGlueBubble
And if you think my code is ugly and feel the need to tell me, it only means we have something in common.

------------------
Fortress of Die Nacht: An upcoming game from Aviary Productions.
Go take a look! | FoDN Progress Log
andiyar
QUOTE
Originally posted by theGlueBubble:
And if you think my code is ugly and feel the need to tell me, it only means we have something in common.



Your code is ugly.

The game so far isn't, though. Oh, BTW, you have been mentioning a 'weekend' fixing up another release.... in the true tradition of software developers, you haven't said which weekend, which year or which decade. I salute you!


-Andiyar

------------------
"Any good that I may do here, let me do now, for I may not pass this way again"
shayborg
Don't know if this'll help, but I don't think you can read and write to the same stream simultaneously. The way it works, at least in Java, is that opening an input stream opens a file to what works as a buffer and reads it as you traverse the file in the program, and writing to the file does the same thing except that it writes whatever you want to a buffer and then overwrites the previous file. Doing both simultaneously probably will cause severe borkage, as I understand it.

------------------
Visit my EVO web site at http://www.evoverride.com!
"Whether 'tis better in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles and by opposing end them ... But you don't do either. Neither suffer nor oppose. You just abolish the slings and arrows. It's too easy." -- John the Savage, Brave New World
theGlueBubble
QUOTE
Originally posted by shayborg:
Don't know if this'll help, but I don't think you can read and write to the same stream simultaneously.  The way it works, at least in Java, is that opening an input stream opens a file to what works as a buffer and reads it as you traverse the file in the program, and writing to the file does the same thing except that it writes whatever you want to a buffer and then overwrites the previous file.  Doing both simultaneously probably will cause severe borkage, as I understand it.



I've performed tests with the same basic idea, I believe. Anyway, I'll probably just declare an input and output stream and use the seekg(), seekp(), tellg(), and tellp() functions to perform what I tried to do with an input/output stream.

------------------
Fortress of Die Nacht: An upcoming game from Aviary Productions.
Go take a look! | FoDN Progress Log
The Thought Police
I understand your pain.

You don't EVER want to see the mess I create in VB.

------------------
[This message has been edited by God (edited 20-20-6003).]
headeater
Don't you go in for comments?
Oh - and have you considered breaking that thing up into smaller functions? It might make things a little easier to debug...

------------------
"The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts."
- Bertrand Russell
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.