Guest User

Untitled

a guest
Apr 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.93 KB | None | 0 0
  1. // ASCII LEGEND BUILD 0.4
  2.  
  3. // [MYFIRSTCHEMISTRYSET]
  4.  
  5. // --- NEW FEATURES ---
  6.  
  7. --> Switch and Write blocks work in the dialogue system.
  8. --> "S" coordinates now available in the collision map. These are checked instantly when stepped upon and link to a dialogue index.
  9.  
  10.  
  11. #include <iostream>
  12. #include <fstream>
  13. #include <string>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <conio.h>
  17. #include <sstream>
  18. #include <windows.h>
  19. #include <vector>
  20. using namespace std;
  21.  
  22. // This is required for the resize function.
  23.  
  24. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  25.  
  26. // Global variables that relate to the display technique.
  27.  
  28. char ActDisp[25][61]; // This is the active display array. For each character movement the map is re-loaded into the array to overwrite the previous "frame" and the avatar file is loaded and written on top of this according to his new location
  29. int rcnt=25; // rcnt and ccnt are integers used as counters for all the display functions. I did this so when I was fooling around with the display size I wouldn't have to change like 50 differnt values each time.
  30. int ccnt=60;
  31.  
  32. // *** message ***
  33.  
  34. // DEBUG FUNCTION
  35.  
  36. // Header message function -- This is the function that displays all that info you see at the top. For the actual game we'll probably change this to the name of the current location.
  37.  
  38. int message (string map, int x, int y, char CrPs)
  39.  
  40. {
  41. // INPUT -- The name of the current map, character's current position (CharPosX, CharPosY) and the collision key relevant to the coordinates (CrPs)
  42. // OUTPUT -- Displays the message bar at the top. No return value.
  43.  
  44. // --- ACCOMPLISHED USING ---
  45.  
  46. // Simple variables and output.
  47.  
  48. // --- PROGRESSION ---
  49.  
  50. // 1) Input the name of the current map, coordinates af the characters top left corner and the value of the coordinates directly beneath his feet.
  51. // 2) Organizes that info along with instructions into a message header outputted at the top of the screen.
  52.  
  53.  
  54. y=y+2; // Relates to the coordinate adjustments. (I should probably just take off the +2 for both and then the values will correspond correctly to the indexes you'll create.)
  55. x=x+2;
  56. cout<<"---ASCII Legend Core Version 0.2---"<<endl<<endl<<"---Use the arrow keys to navigate---"<<endl<<endl<<"---Press Q to explore and interact---"<<endl<<endl; // Instructions.
  57. cout<<map<<endl<<endl; // Output the name of the map.
  58. cout<<"Coordinates - "<<x<<" "<<y<<endl<<endl; // Output the x and y coordinates modiefied earlier.
  59. cout<<"Underfoot - "<<CrPs<<endl<<endl; // Output the Square directly underneath the character (I may incorporate something like this into the actual game interface so you can see what you're standing on in a little box on the bottom.)
  60.  
  61. return 0;
  62. }
  63.  
  64. // *** resize ***
  65.  
  66. // CORE FUNCTION
  67.  
  68. // This function will resize the console window to allow for a larger play area. I'm not exactly sure how it works specifically but I'll show you how to use it below.
  69.  
  70. int resize(int bottom)
  71. {
  72. // INPUT -- Probably nothing. I was going to to use variables to adjust the size whenever we want but if were using a static resolution we can just set it the one time.
  73. // OUTPUT -- Changes the screen size. In this case it just adjusts the bottom by 20 units.
  74.  
  75. HANDLE hOut;
  76. CONSOLE_SCREEN_BUFFER_INFO SBInfo;
  77. SMALL_RECT DisplayArea = {0, 0, 0, 0};
  78. int x;
  79. int y;
  80.  
  81. hOut = GetStdHandle( STD_OUTPUT_HANDLE );
  82.  
  83. GetConsoleScreenBufferInfo(hOut,
  84. &SBInfo);
  85.  
  86. x = SBInfo.srWindow.Right;
  87. y = SBInfo.srWindow.Bottom;
  88.  
  89. // This part is what's used to adjust the window size. The first two values adjust the upper left corner and the bottom two values adjust the lower right corner.
  90. // If the change can't be made, nothing will happen.
  91.  
  92. DisplayArea.Left = 0;
  93. DisplayArea.Top = 0;
  94. DisplayArea.Right = x;
  95. DisplayArea.Bottom = y+20;
  96.  
  97. SetConsoleWindowInfo(hOut,TRUE,&DisplayArea);
  98.  
  99. return 0;
  100. }
  101.  
  102. // ***InfoBar***
  103.  
  104. // Very simple function for recieving and outputting messages below the navigation view.
  105.  
  106. int InfoBar (string InfoBar) // Fairly self explainatory - InfoBar is a string containing the value to be outputted.
  107. {
  108. cout<<endl<<" "<<InfoBar; // The message is tabulated and outputted.
  109.  
  110. return 0; // No return values.
  111. }
  112.  
  113. int DispRecall ()
  114. {
  115. char ActD[25][61];
  116. ifstream myfile("ActDisp.txt");
  117.  
  118. int row = 0;
  119. int col = 0;
  120.  
  121. while(row <= rcnt)
  122. {
  123. while(col <= ccnt)
  124. {
  125. myfile.get(ActD[row][col]);
  126. col++;
  127. }
  128. col = 0;
  129. row++;
  130. }
  131.  
  132. for(int row = 0; row < rcnt-1; row++)
  133. {
  134. for(int col = 0; col < ccnt; col++)
  135. {
  136. cout <<ActDisp[row][col];
  137. }
  138. cout <<endl;
  139. }
  140.  
  141. return 0;
  142. }
  143.  
  144. // *** StringSave ***
  145.  
  146. // CORE FUNCTION
  147.  
  148. // Saves a string to a specific line of a specific file as specified by the input.
  149.  
  150. int StringSave (string Val, int Ln, string FlNm) {
  151.  
  152. // 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).
  153. // OUTPUT --- Just the change made to the text file. No return value.
  154.  
  155. // ACCOMPLISHED USING
  156.  
  157. // 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.
  158. // The vector is then written back into the file one line at a time.
  159.  
  160. string n; // Counter for push_back.
  161. vector <string> v; // Vector for storing file contents of variable length.
  162. 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.
  163.  
  164. ifstream myfile(FlNm); // Load the specified file.
  165.  
  166. while (getline( myfile, n )) // Store the contents of the specified file into a vector line by line and cell by cell.
  167. {
  168. v.push_back( n );
  169. count++; // Records the number of lines in the text file.
  170. }
  171.  
  172. myfile.close(); // Close the file.
  173.  
  174. v[Ln] = Val; // Store the text to be saved into the appropriate cell of the vector.
  175.  
  176. ofstream myfile2(FlNm); // Re-open the specified file.
  177. 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)
  178. while (i<count){
  179. myfile2<<v[i]<<"\n"; // Write each cell of the vector into the specified file, separted by \n
  180. i++;
  181. }
  182.  
  183. myfile2.close(); // Close the file.
  184.  
  185. return 0;
  186.  
  187. }
  188. // *** stringAdd ***
  189.  
  190. // CORE FUNCTION
  191.  
  192. // Adds any string value to an additional line on the end of a referenced text file.
  193.  
  194. void stringAdd (string Val, string FlNm) {
  195.  
  196. ofstream myfile2(FlNm);
  197.  
  198. myfile2<<Val<<"\n";
  199.  
  200. }
  201.  
  202. // **** LoadString ****
  203.  
  204. // CORE FUNCTION
  205.  
  206. // Loads a string value from a text file according to the line reference given and the name of the file. The value corresponds to the entire contents of that line.
  207.  
  208. string LoadString (int Ln, string Nm){
  209.  
  210. // INPUT -- The line number you want to load (Ln) and the name of the file you want to load it from (Nm).
  211. // OUTPUT -- Returns that string value.
  212.  
  213. // -- ACCOMPLISHED USING --
  214.  
  215. // 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.
  216.  
  217. // -- PROGRESSION --
  218.  
  219. // 1) Input the line number and filename.
  220. // 2) Declare neccessary variables.
  221. // 3) Load the file based on the name given.
  222. // 4) Read from the file one line at a time into consecutive cells of the vector.
  223. // 5) Reference the contents of the line specified by accessing the corresponding vector cell.
  224. // 6) Return the loaded value.
  225.  
  226. string n; // Counter used for push_back.
  227. vector <string> v; // Vector for storing the contents of the source files. Allows for storage of the contents of text files of varying length.
  228.  
  229. ifstream myfile(Nm); // Load the file specified above.
  230.  
  231. 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.
  232.  
  233. {
  234. v.push_back( n );
  235. }
  236.  
  237. myfile.close(); // Close the file.
  238.  
  239. return v[Ln]; // Return the contents of the line specified.
  240. }
  241.  
  242. void saveGame () {
  243.  
  244. cout<<" -- Saved w -- ";
  245. string index;
  246. string sSlot="Slot1/";
  247. string Flnm;
  248. string Query;
  249. int q;
  250. int car=0;
  251. int Choice = 0;
  252. int Op = 0;
  253. int loop = 0;
  254. int count = 0;
  255. bool Cancel=false;
  256. string root;
  257. string dest;
  258.  
  259.  
  260. for (int menu=0; menu<2; menu++){
  261. cout<<endl<<"menu = "<<menu;
  262. Choice = 0;
  263. system ("PAUSE");
  264. do { // This loop contains the item menu and will continue until the player chooses to ignore the item or pick it up.
  265.  
  266. do{ // This loop will continue to recieve keystroke input until the character hits the action key.
  267. cout<<endl<<"yup";
  268. if (car==80) // If the keystroke is the down arrow.
  269. {
  270. 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.
  271. if (Choice>2){ // Argument to check if the lowermost choice is already highlighted.
  272. Choice =2; // If so the choice remains the same.
  273. }
  274. }
  275.  
  276. else if (car==72) // Same as above but for the up arrow.
  277. {
  278. Choice--;
  279. if (Choice<0){
  280. Choice = 0;
  281. }
  282.  
  283. }
  284. Query = "hmm...";
  285.  
  286. if (menu==0){
  287. if (Choice == 0){ // Arguments associated with "highlighting" the correct menu choice based on the variable "Choice."
  288. Query = "Save Menu \n Save <-- \n Load \n Cancel";
  289. }
  290. else if (Choice == 1){
  291. Query = "Save Menu \n Save \n Load <-- \n Cancel";
  292. }
  293. else if (Choice == 2){
  294. Query = "Save Menu \n Save \n Load \n Cancel <--";
  295. }
  296. }
  297.  
  298. if (menu==1){
  299. if (Choice == 0){ // Arguments associated with "highlighting" the correct menu choice based on the variable "Choice."
  300. Query = "Which Slot? \n Slot1 <-- \n Slot2 \n Cancel";
  301. }
  302. else if (Choice == 1){
  303. Query = "Which Slot? \n Slot1 \n Slot2 <-- \n Cancel";
  304. }
  305. else if (Choice == 2){
  306. Query = "Which Slot? \n Slot1 \n Slot2 \n Cancel";
  307. }
  308. }
  309.  
  310. system("CLS"); // Clear the screen.
  311. cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<car<<endl<<endl<<endl<<endl<<endl<<"Item"<<endl<<endl<<endl<<endl; // DEBUG -- Placeholder for the debug message bar.
  312.  
  313. DispRecall(); // Write a snapshot if the scene.
  314. InfoBar(Query); // Followed by the menu with the correct choice highlighted.
  315.  
  316. cout<<" car = "<<car;
  317.  
  318. }while((car=getch())!=113&&(car=getch())!=81); // Continue until the action key is entered.
  319.  
  320. if (menu==0){
  321.  
  322. if (Choice == 0){ // If the player chose to examine the item, the examine function is called on to accomplish this.
  323. Op = 0;
  324. Choice = 2;
  325. }
  326. else if (Choice == 1){ // If the player chose to pick the item up, the properties associated with the item are written into the appropriate files.
  327. Op = 1;
  328. Choice = 2;
  329. }
  330. else if (Choice == 2){
  331. Choice = 3;
  332. }
  333.  
  334. }
  335.  
  336. if (menu==1){
  337.  
  338. if (Choice == 0){ // If the player chose to examine the item, the examine function is called on to accomplish this.
  339. sSlot = "Slot1/";
  340. Choice = 2;
  341. }
  342. else if (Choice == 1){ // If the player chose to pick the item up, the properties associated with the item are written into the appropriate files.
  343. }
  344. sSlot = "Slot2/";
  345. Choice = 2;
  346. }
  347. else if (Choice == 2){
  348. Choice = 3;
  349. }
  350.  
  351. } while (Choice!=2&&Choice!=3);
  352. }
  353. cout<<" Choice -- "<<Choice;
  354.  
  355. if (Choice!=3){
  356. cout<<endl<<" Running Save "<<Op<<" "<<sSlot;
  357.  
  358. if (Op == 0){
  359. root = "char/";
  360. dest = "char/"+sSlot;
  361. }
  362. if (Op == 1)
  363. root = "char/"+sSlot;
  364. dest = "char/";
  365.  
  366. while (loop<3){
  367.  
  368. //cout<<endl<<endl<<" loop = "<<loop<<endl<<endl;
  369.  
  370. if (loop==0)
  371. Flnm = "Char.txt";
  372. else if (loop==1)
  373. Flnm = "Inventory.txt";
  374. else if (loop==2)
  375. Flnm = "Battle.txt";
  376.  
  377.  
  378. system("PAUSE");
  379.  
  380. loop++;
  381.  
  382. string n; // Counter for push_back.
  383. vector <string> v; // Vector for storing file contents of variable length.
  384. // 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.
  385.  
  386. ifstream myfile("char/"+Flnm); // Load the specified file.
  387.  
  388. count = 0;
  389.  
  390. if (myfile.good()){
  391. //cout<<"char/"<<Flnm<<" ";
  392. while (getline( myfile, n )) // Store the contents of the specified file into a vector line by line and cell by cell.
  393. {
  394. v.push_back( n );
  395. count++; // Records the number of lines in the text file.
  396. }
  397.  
  398. myfile.close(); // Close the file.
  399.  
  400. ofstream myfile2("char/"+sSlot+Flnm); // Re-open the specified file.
  401. if (myfile2.good()){
  402. cout<<" "<<root<<Flnm<<" to "<<dest<<sSlot<<Flnm;
  403. q = 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)
  404. //cout<<endl<<endl<<"count = "<<count;
  405. if (count!=0){
  406. while (q<count){
  407. myfile2<<v[q]<<"\n"; // Write each cell of the vector into the specified file, separted by \n
  408. q++;
  409. }
  410. }
  411.  
  412. //cout<<" -- Written";
  413.  
  414. myfile2.close(); // Close the file.
  415. }
  416. }
  417. }
  418. }
  419.  
  420. string n3; // Counter for push_back.
  421. vector <string> v3; // Vector for storing file contents of variable length.
  422. // 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.
  423.  
  424. ifstream myfile3("char/Char.txt"); // Load the specified file.
  425.  
  426. count = 0;
  427. index = "hello";
  428.  
  429. if (myfile3.good()){
  430.  
  431. cout<<endl<<" hello 2 " <<index;
  432.  
  433.  
  434. while (getline( myfile3, n3 )) // Store the contents of the specified file into a vector line by line and cell by cell.
  435. {
  436. v3.push_back( n3 );
  437. count++; // Records the number of lines in the text file.
  438. }
  439. }
  440.  
  441. index = "Maps/Map"+v3[0]+"_"+v3[1]+"/"+"99_99_X_"+v3[0]+"_"+v3[1]+".txt";
  442.  
  443. cout<<endl<<index;
  444.  
  445.  
  446. system("PAUSE");
  447.  
  448. //StringSave(v3[0],0,index);
  449. //StringSave(v3[1],1,index);
  450. //StringSave(v3[3],3,index);
  451. //StringSave(v3[4],4,index);
  452. }
  453.  
  454.  
  455.  
  456.  
  457. // *** HeroWrite ***
  458.  
  459. // FUTURE CORE FUNCTION
  460.  
  461. // This function will load the active hero source file and modify it based on a key item which has been picked up.
  462.  
  463. // INPUT --- The current hero file and a file containing the new look.
  464. // OUTPUT -- The modification to the active hero file. No return value.
  465.  
  466. //char Heroload (char h[6][3]) // This will load the hero avatar into an array from it's source file
  467. //{
  468. // char hero [6][3];
  469. //
  470. // ifstream myfile("Hero.txt");
  471. //
  472. // for(int row = 0; row < 5; row++)
  473. // {
  474. // for(int col = 0; col < 8; col++)
  475. // {
  476. // myfile.get(hero[row][col]);
  477. // }
  478. // }
  479. // return hero[6][3];
  480. //}
  481.  
  482. // *** UnderFoot ***
  483.  
  484. // CORE FUNCTION
  485.  
  486. // Reads the character in the collision file corresponding to the character's current coordinates and returns it.
  487.  
  488. char UnderFoot (int x, int y, string Clsn){
  489.  
  490. // INPUT --- The character's coordinates (CharPosx, CharPosy) and the name of the collision file (Clsn).
  491. // OUTPUT --- The character value corresponding to the character's position.
  492.  
  493. // --- ACCOMPLISHED USING ---
  494.  
  495. // Simple file I/O, multidimentsional arrays and a while loop with counters (Again, I tried for loops out originally but they didn't work for whatever reason - GG).
  496.  
  497. // --- PROGRESSION ---
  498.  
  499. // 1) Input the character's coordinates and the name of the relevant collision map.
  500. // 2) Write the contents of the collision file into a temporary 2D array.
  501. // 3) Access the appropriate cell using the provided coordinates
  502. // 4) Return that value
  503.  
  504. char ClsnAr[25][61]; // Declaring the temporary multi-dimensional array to store the contents of the collsion file.
  505.  
  506. ifstream myfile(Clsn); // Open the specified collision file.
  507.  
  508. int row = 0; // Counters for the while loops below.
  509. int col = 0;
  510.  
  511. while(row <= rcnt) // These loops will write into the temporary array from the specified file one character at a time.
  512. {
  513. while(col <= ccnt)
  514. {
  515. myfile.get(ClsnAr[row][col]);
  516. col++;
  517. }
  518. col = 0;
  519. row++;
  520. }
  521.  
  522. return ClsnAr[y+2][x+2]; // Return the character value at the the specified coordinates.
  523. }
  524.  
  525. // ***CollisionCheck***
  526.  
  527. // CORE FUNCTION
  528.  
  529. // During exploration, this function will examine the intended move and will not allow it to occur if there's a barrier on the intended destination.
  530.  
  531. bool CollisionCheck (int car, int CharPosx, int CharPosy, string Clsn)
  532. {
  533.  
  534. // (((( GG - I may combine this with the pre-check used in transitions - they do essentially the same thing.
  535.  
  536. // INPUT --- The players keystroke (car), his position (CharPosX, CharPosy) and the name of the current collision map (Clsn).
  537. // OUTPUT --- Returns a boolean value which is true if a collision will occur or false if it won't.
  538.  
  539. // --- ACCOMPLISHED USING ---
  540.  
  541. // Simple file I/O. Multidimensional arrays, while and if loops.
  542.  
  543. // --- PROGRESSION ---
  544.  
  545. // 1) input is recieved.
  546. // 2) A boolean variable is initialized as false to act as the collision flag.
  547. // 3) The collision map is loaded and stored in a temporary 2D array.
  548. // 4) The 4 corners of the character's avatar are checked against the array to determine if any of them contain asterixes. These arguments factor in the characters keystroke to determine the intended destination.
  549. // 5) If any of the 4 corners will overlap with asterixes the collision flag will become true.
  550. // 6) The collision flag is returned. If it's true the move won't occur and if it's true the move will occur.
  551.  
  552. bool Clsn1_1 = false; // Declaring the collision flag as false.
  553. char ActD[25][61]; // Declaring a temporary 2D array to match the dimensions of the collision source file.
  554.  
  555. ifstream myfile(Clsn); // Load the specified collision map.
  556.  
  557. int row = 0; // Counter integers for while loop
  558. int col = 0;
  559.  
  560. while(row <= rcnt) // While loop to write the contents of the collision file into the 2D array.
  561. {
  562. while(col <= ccnt)
  563. {
  564. myfile.get(ActD[row][col]);
  565. col++;
  566. }
  567. col = 0;
  568. row++;
  569. }
  570.  
  571. // Arguments to determine if there is an asterix at his intended destination. Accomplished by considering the characters keystroke and current position.
  572.  
  573. // If the character is moving up -
  574.  
  575. if (car==72){ // Up
  576. if (ActD[CharPosy-1][CharPosx] == '*') // Check the intended destination of his top left corner...
  577. Clsn1_1 = true;
  578. else if (ActD[CharPosy-1][CharPosx+4] == '*') // ... and his top right corner (the other corners wouldn't be relevant to this move).
  579. Clsn1_1 = true;
  580. }
  581.  
  582. // If they move right -
  583.  
  584. else if (car==77){ // Right
  585. if (ActD[CharPosy][CharPosx+5] == '*') // Check the destination of the top right...
  586. Clsn1_1 = true;
  587. else if (ActD[CharPosy+2][CharPosx+5] == '*') // ...and the bottom right.
  588. Clsn1_1 = true;
  589.  
  590. }
  591.  
  592. // For left -
  593.  
  594. else if (car==75){ // Left
  595. if (ActD[CharPosy][CharPosx-1] == '*') // Top left.
  596. Clsn1_1 = true;
  597. else if (ActD[CharPosy+2][CharPosx-1] == '*') // Bottom left.
  598. Clsn1_1 = true;
  599.  
  600. }
  601.  
  602. // Down -
  603.  
  604. else if (car==80){ // Down
  605. if (ActD[CharPosy+3][CharPosx] == '*') // Lower left.
  606. Clsn1_1 = true;
  607. else if (ActD[CharPosy+3][CharPosx+4] == '*') // Lower right.
  608. Clsn1_1 = true;
  609. }
  610.  
  611. return Clsn1_1; // Return the collision flag.
  612. }
  613.  
  614.  
  615.  
  616.  
  617. // ***HeroWrite***
  618.  
  619. // This function re-writes the map and avarar information according to the character's new coordinates. It will also display a question mark above the hero's head if there is a "D" underfoot.
  620.  
  621. int HeroWrite (int x, int y, char ActD[25][61], string map, char UndrFt){
  622.  
  623. // (((( GG - I may leave this one or create a new write function to write any source file into the scene and use it to write the hero as well.
  624. // (((( We can use this to create scripted sequences with simple movement of other characters, objects and enemies.
  625. // (((( We can also use it to write temporary obstacles and whatnot into a map.
  626.  
  627. // INPUT --- The character's position (CharPosX, CharPosY), the current contents of the active display array and the name of the current map. Also the character value under the character's feet (CrntPos).
  628. // OUTPUT --- The character is displayed on the screen in their new position. No return value.
  629.  
  630. // --- ACCOMPLISHED USING ---
  631.  
  632. // Simple file I/O, 2D arrays and while loops.
  633.  
  634. // --- PROGRESSION ---
  635.  
  636. // 1) Recieve input.
  637. // 2) Load the map file into a temporary array (ActDisp).
  638. // 3) Load the hero file into a temporary array (Hero).
  639. // 4) Write the hero into the array containing the map information based on coordinates.
  640. // 5) Check the value underneath the character's feet. If it's "D" a question mark will be written above the avatar's head.
  641. // 6) Output the complete array on screen.
  642.  
  643. char Hero[4][6]; // Declare the temporary variable to contain the hero.
  644. ifstream myfile2(map); // Load the specified map file.
  645. ifstream myfile("Hero.txt"); // Load the source file containing the look of the hero.
  646.  
  647. int row = 0; // Counters for the while loop.
  648. int col = 0;
  649.  
  650. while(row <= rcnt)
  651. {
  652. while(col <= ccnt)
  653. {
  654. myfile2.get(ActDisp[row][col]); // Store the contents of the map file in the temporary map array.
  655. col++;
  656. }
  657. col = 0;
  658. row++;
  659. }
  660.  
  661.  
  662. int rowa = 0; // More counters.
  663. int cola = 0;
  664.  
  665. while(rowa <= 4)
  666. {
  667. while(cola <= 6)
  668. {
  669. myfile.get(Hero[rowa][cola]); // Store the contents of the hero file in the hero array.
  670. cola++;
  671. }
  672. cola = 0;
  673. rowa++;
  674. }
  675.  
  676. for (int l=0; l<3; l++){
  677. for (int m=0; m<5; m++){
  678.  
  679. /*if (Hero[l][m]!=' ')*/
  680. ActD[y+l][x+m]=Hero[l][m];
  681.  
  682. }
  683. cout<<endl;
  684. }
  685.  
  686. if (UndrFt == 'D') // If loop for checking the space underneath the character.
  687. ActD[y-1][x+2]='?'; // If the value is "D" a question mark is written at the appropriate coordinates.
  688.  
  689. for(int row = 0; row < rcnt-1; row++)
  690. {
  691. for(int col = 0; col < ccnt; col++)
  692. {
  693. cout <<ActDisp[row][col]; // Output the scene to the display.
  694. }
  695. cout <<endl;
  696. }
  697. return 0; // No return value.
  698. }
  699.  
  700.  
  701.  
  702. // ***IndexCall***
  703.  
  704. // This is a function for generating the name of an index based on coordinates and the type of square specified.
  705.  
  706. string IndexCall (int x, int y, string A)
  707. {
  708. // INPUT -- The character's coordinates (CharPosx, CharPosy) and the index letter (string input corresponding to the letter in the index).
  709. // OUTPUT -- Assembles and returns an index filename corresponding to the coordinates.
  710.  
  711. string tmp; // String for containing the filename.
  712. string chp = LoadString(0, "char/Char.txt"); // The chapter value is loaded from the character file using the LoadString function.
  713. string mp = LoadString(1, "char/Char.txt"); // The map value is loaded from the character file in the same manner.
  714.  
  715. ofstream myfile2 ("Temp.txt"); // Load a temporary file to store the filename.
  716. myfile2<<"Maps/"<<"Map"<<chp<<"_"<<mp<<"/"<<chp<<"_"<<mp<<"_"<<A<<"_"<<x<<"_"<<y<<".txt"; // Assemble the syntax of the index.
  717. myfile2.close(); // Close the file.
  718.  
  719. ifstream myfile3("Temp.txt"); // Load the file containing the index name.
  720. getline (myfile3, tmp);
  721. myfile3.close();
  722.  
  723. return tmp; // Return the complete index filename.
  724.  
  725. }
  726.  
  727.  
  728. // ***Examine***
  729.  
  730. // CORE FUNCTION
  731.  
  732. // Function for reading and outputting regular descriptions from source files. Occurs if the coordinates feature a normal description or if "Examine" is chosen from a menu.
  733.  
  734. string Examine(int x, int y)
  735. {
  736.  
  737. // INPUT --- The character's coordinates (CharPosX, CharPosY).
  738. // OUTPUT --- Displays a description relating to the characters current coordinates.
  739.  
  740. // ACCOMPLISHED USING
  741.  
  742. // Simple file I/O and vectors.
  743.  
  744. // PROGRESSION
  745.  
  746. // 1) Recieve input
  747. // 2) Generate the appropriate index filename from coordinates
  748. // 3) Call on the index and read the contents into a vector
  749. // 4) Store the contents of the index in the appropriate variables for driving the description
  750. // 5) Re-display a snapshot of the same scene with the description appearing in the info bar below.
  751. // 6) Await action key keystroke as que to bring up the next page.
  752. // 7) Repeat steps 5 and 6 for additional pages in the
Add Comment
Please, Sign In to add comment