daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <conio.h>
  7. #include <sstream>
  8. #include <windows.h>
  9. #include <vector>
  10. using namespace std;
  11.  
  12. void stringAdd (string Val, string FlNm) {
  13.  
  14.     ofstream myfile2(FlNm);
  15.  
  16.     myfile2<<Val<<"\n";
  17.  
  18. }
  19.  
  20. int StringSave (string Val, int Ln, string FlNm) {
  21.  
  22.     // INPUT --- The value to be deposited in the file (Val), an integer corresponding to the line number (Ln) and the name of the file it will be saved in (FlNm).
  23.     // OUTPUT --- Just the change made to the text file. No return value.
  24.  
  25.     // ACCOMPLISHED USING
  26.    
  27.     // Works similarly to the above StringLoad function. The contents of the specified file are loaded into a vector and a cell in that vector are modified using a line number.
  28.     // The vector is then written back into the file one line at a time.
  29.  
  30.     string n; // Counter for push_back.
  31.     vector <string> v; // Vector for storing file contents of variable length.
  32.     int count = 0; // Integer counter that will count how many lines the file is when it's written into the vector. This is called on later when the vector is written back into the file.
  33.  
  34.     ifstream myfile(FlNm); // Load the specified file.
  35.  
  36.     while (getline( myfile, n )) // Store the contents of the specified file into a vector line by line and cell by cell.
  37.     {
  38.     v.push_back( n );
  39.     count++; // Records the number of lines in the text file.
  40.     }
  41.  
  42.     myfile.close(); // Close the file.
  43.  
  44.     v[Ln] = Val; // Store the text to be saved into the appropriate cell of the vector.
  45.  
  46.     ofstream myfile2(FlNm); // Re-open the specified file.
  47.     int i = 0; // Counter for while loop. (While writing the HeroWrite function I originally used for loops for this but it didn't seem to work properly - GG)
  48.     while (i<count){
  49.         myfile2<<v[i]<<"\n"; // Write each cell of the vector into the specified file, separted by \n
  50.         i++;
  51.     }
  52.  
  53.     myfile.close(); // Close the file.
  54.  
  55.     return 0;
  56.  
  57. }
  58.  
  59. int InfoBar (string InfoBar) // Fairly self explainatory - InfoBar is a string containing the value to be outputted.
  60.     {
  61.         cout<<endl<<"   "<<InfoBar; // The message is tabulated and outputted.
  62.        
  63.         return 0; // No return values.
  64.     }
  65.  
  66. string LoadString (int Ln, string Nm){
  67.  
  68.     // INPUT -- The line number you want to load (Ln) and the name of the file you want to load it from (Nm).
  69.     // OUTPUT -- Returns that string value.
  70.  
  71.     // -- ACCOMPLISHED USING --
  72.  
  73.     // This function uses vectors as storage containers of variable size for storing the contents of text files. The push_back command is used to store into the variable one cell at a time.
  74.  
  75.     // -- PROGRESSION --
  76.  
  77.     // 1) Input the line number and filename.
  78.     // 2) Declare neccessary variables.
  79.     // 3) Load the file based on the name given.
  80.     // 4) Read from the file one line at a time into consecutive cells of the vector.
  81.     // 5) Reference the contents of the line specified by accessing the corresponding vector cell.
  82.     // 6) Return the loaded value.
  83.  
  84.     string n; // Counter used for push_back.
  85.     vector <string> v; // Vector for storing the contents of the source files. Allows for storage of the contents of text files of varying length.
  86.  
  87.     ifstream myfile(Nm); // Load the file specified above.
  88.  
  89.     while (getline( myfile, n )) // Loop which will continue to store the contents of the source file line by line into the vector until the end of the file is reached.
  90.  
  91.     {
  92.     v.push_back( n );
  93.     }
  94.  
  95.     myfile.close(); // Close the file.
  96.  
  97.     return v[Ln]; // Return the contents of the line specified.
  98. }
  99.  
  100. // *** LoadInt ***
  101.  
  102. // POTENTIAL FUNCTION
  103.  
  104. // Loads an integer value from a text file according to the line reference given.
  105. // Will work similarly to StringLoad.
  106. // Probably won't be required as it's relatively easy to convert the values returned from the LoadString function to integer.
  107.  
  108. int LoadInt (){
  109.  
  110.     int Loaded;
  111.  
  112.     return Loaded;
  113. }
  114.  
  115. string IndexCall (int x, int y, string A)
  116. {
  117.     // INPUT -- The character's coordinates (CharPosx, CharPosy) and the index letter (string input corresponding to the letter in the index).
  118.     // OUTPUT -- Assembles and returns an index filename corresponding to the coordinates.
  119.  
  120.     string tmp; // String for containing the filename.
  121.     string chp = LoadString(0, "char/Char.txt"); // The chapter value is loaded from the character file using the LoadString function.
  122.     string mp = LoadString(1, "char/Char.txt"); // The map value is loaded from the character file in the same manner.
  123.  
  124.     ofstream myfile2 ("Temp.txt"); // Load a temporary file to store the filename.
  125.     myfile2<<"Maps/"<<"Map"<<chp<<"_"<<mp<<"/"<<chp<<"_"<<mp<<"_"<<A<<"_"<<x<<"_"<<y<<".txt"; // Assemble the syntax of the index.
  126.     myfile2.close(); // Close the file.
  127.  
  128.     ifstream myfile3("Temp.txt"); // Load the file containing the index name.
  129.     getline (myfile3, tmp);
  130.     myfile3.close();
  131.  
  132.     return tmp; // Return the complete index filename.
  133.  
  134. }
  135.  
  136. void dialogue(int x, int y){
  137.  
  138. string n;
  139. string n2;
  140. vector <string> v;
  141. vector <string> v2;
  142. string Index = IndexCall(x, y, "L");
  143. int i=0;
  144. int Choice=0;
  145. int car=0;
  146. int Ln = 0;
  147. int ChCnt;
  148. int temp;
  149. int Count2=0;
  150.  
  151. string Query;
  152.  
  153. cout<<Index<<endl<<endl;
  154.  
  155. ifstream myfile(Index); // Load the index file.
  156.  
  157. if (myfile.good()){
  158. while (getline( myfile, n )) // Store the contents in the temporary vector.
  159. {
  160. v.push_back( n );
  161. }
  162.    
  163. myfile.close();
  164.  
  165. cout<<endl<<endl<<"Loaded";
  166.  
  167. system ("PAUSE");
  168.  
  169. }
  170.  
  171.  
  172.     do { // This loop contains the item menu and will continue until the player chooses to ignore the item or pick it up.
  173.        
  174.         cout<<endl<<endl<<v[Ln]<<endl;
  175.  
  176.         if (v[Ln] == "D"){
  177.             InfoBar(v[Ln+1]+"\n   "+v[Ln+2]+"\n   "+v[Ln+3]+"\n");
  178.             istringstream ( v[Ln+4] ) >> Ln;
  179.             cout<<endl<<endl<<v[Ln];
  180.             system ("PAUSE");
  181.         }
  182.  
  183.         else if (v[Ln] == "S"){
  184.            
  185.             ifstream myfile2(v[Ln+2]); // Load the index file.
  186.             Count2 =  0;
  187.             if (myfile2.good()){
  188.                 cout<<endl<<endl<<"S - Source Loaded"<<endl<<endl;
  189.             while (getline( myfile2, n2 )) // Store the contents in the temporary vector.
  190.             {
  191.             v2.push_back( n2 );
  192.             Count2++;
  193.             }
  194.    
  195.             myfile.close();
  196.  
  197.             if (Count2!=0){
  198.  
  199.             if (v[Ln+1] == "ALL"){
  200.                 cout<<endl<<endl<<"ALL"<<endl<<endl;
  201.                 temp = Ln;
  202.                 istringstream ( v[Ln+5] ) >> Ln;
  203.                 i = 0;
  204.                 while (i<Count2){
  205.                     if (v2[i] == v[Ln+3])
  206.                     Ln = temp;
  207.                     istringstream ( v[Ln+4] ) >> Ln;
  208.                     cout<<endl<<endl<<"Checking "<<v2[i]<<" vs "<<v[Ln+3]<<" go to "<<Ln;
  209.                     i++;
  210.                 }
  211.             }
  212.             else
  213.             {
  214.  
  215.                 istringstream ( v[Ln+1] ) >> temp;
  216.                 cout<<endl<<endl<<"Line "<<temp<<endl<<endl;
  217.                 istringstream ( v[Ln+5] ) >> Ln;
  218.                 if (v2[temp] == v[Ln+3])
  219.                         istringstream ( v[Ln+4] ) >> Ln;
  220.  
  221.             }
  222.             }
  223.            
  224.             else
  225.             {
  226.             cout<<endl<<endl<<"SMALL"<<endl<<endl;
  227.             istringstream ( v[Ln+5] ) >> Ln;
  228.             }
  229.             }
  230.             system ("PAUSE");
  231.  
  232.         }
  233.  
  234.         else if (v[Ln] == "W") {
  235.             if (v[Ln+1] == "ADD"){
  236.                 cout<<endl<<endl<<"W - ADD "<<v[Ln+3]<<" "<<v[Ln+2]<<v[Ln+1]<<endl<<endl;
  237.                 stringAdd(v[Ln+3],v[Ln+2]);
  238.                 istringstream ( v[Ln+4] ) >> Ln;
  239.             }
  240.             else {
  241.                 istringstream ( v[Ln+1] ) >> temp;
  242.                 cout<<endl<<endl<<"W - "<<v[Ln+2]<<v[Ln+3]<<" "<<v[Ln+2]<<temp<<endl<<endl;
  243.                 StringSave(v[Ln+3], temp, v[Ln+2]);
  244.                 istringstream ( v[Ln+4] ) >> Ln;
  245.             }
  246.             system ("PAUSE");
  247.         }
  248.  
  249.         else if (v[Ln] == "C")  {
  250.             do{ // This loop will continue to recieve keystroke input until the character hits the action key.
  251.  
  252.                 if (car==80) // If the keystroke is the down arrow.
  253.             {
  254.                 Choice++; // The value of Choice increases. Within the menu this will constitute highlighting the choice below the previous one, unless the lowermost choice is highlighted.
  255.                 if (Choice>2){ // Argument to check if the lowermost choice is already highlighted.
  256.                     Choice =2; // If so the choice remains the same.
  257.  
  258.                 }
  259.                
  260.             }
  261.  
  262.             else if (car==72) // Same as above but for the up arrow.
  263.             {
  264.                 Choice--;
  265.                 if (Choice<0){
  266.                     Choice = 0;
  267.                 }
  268.  
  269.             }
  270.            
  271.             istringstream (v[Ln+1]) >> ChCnt;
  272.  
  273.             if (ChCnt<3){
  274.                 if (Choice==2)
  275.                     Choice = 1;
  276.                 if (ChCnt==1){
  277.                     if (Choice != 0)
  278.                         Choice = 0;
  279.                 }
  280.             }
  281.                
  282.             if (Choice == 0){ // Arguments associated with "highlighting" the correct menu choice based on the variable "Choice."
  283.                 Query = v[Ln+2]+" <-- \n   "+v[Ln+3]+" \n   "+v[Ln+4];
  284.             }
  285.             else if (Choice == 1){
  286.                 Query = v[Ln+2]+"\n   "+v[Ln+3]+" <-- \n   "+v[Ln+4];
  287.             }
  288.             else if (Choice == 2){
  289.                 Query = v[Ln+2]+"\n   "+v[Ln+3]+" \n   "+v[Ln+4]+" <-- ";
  290.             }
  291.        
  292.             system("CLS"); // Clear the screen.
  293.             cout<<endl<<endl<<endl<<endl<<endl<<Choice<<endl<<endl<<car<<endl<<endl<<endl<<endl<<endl<<"Item"<<endl<<endl<<endl<<endl; // DEBUG -- Placeholder for the debug message bar.
  294.  
  295.             InfoBar(Query); // Followed by the menu with the correct choice highlighted.
  296.            
  297.              }while((car=getch())!=113&&(car=getch())!=81); // Continue until the action key is entered.
  298.        
  299.        
  300.             if (Choice == 0){ // If the player chose to examine the item, the examine function is called on to accomplish this.
  301.                 istringstream (v[Ln+5]) >> Ln;
  302.             }
  303.             if (Choice == 1){ // If the player chose to pick the item up, the properties associated with the item are written into the appropriate files.
  304.                 istringstream (v[Ln+6]) >> Ln;
  305.             }
  306.             if (Choice == 2){
  307.                 istringstream (v[Ln+7]) >> Ln;
  308.             }
  309.         }
  310.  
  311.         else
  312.         {
  313.             cout<<endl<<endl<<"Line type not recognized."<<endl<<endl;
  314.         }
  315.  
  316.  
  317.  
  318.         } while (v[Ln]!="X");
  319.  
  320.  
  321. system("PAUSE");
  322.  
  323. }
  324.  
  325.  
  326. void main (){
  327.  
  328.     int x = 1;
  329.     int y = 1;
  330.  
  331.     dialogue(x,y);
  332.  
  333. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top