1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdio.h>
#include <time.h>
#include <cmath>
using namespace std;
// prototypes for our functions
int main()
{
int dragonHealth, dragonAttack, height;
int rangerHealth, rangerAttack, sorcererHealth, sorcererAttack, fighterHealth, fighterAttack;
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\tDRAGON'S FALL ";
cout << "\n\n\n\nInstructions: You will be guided through the game with menus, and \n";
cout << "Your goal is to defeat the dragon. You have three classes on \n";
cout << "the field. Ranger, sorcerer, and fighter. You will pick any\n";
cout << "placement of the three and fight your way to the dragon. \n";
cout << "\nPress enter to continue\n";
cin.get();
cout << "Goblins are represented with R, Elementals are represented with E,\n";
cout << "and the dragon is represented with D. Items are represented with I,\n";
cout << "trees are represented with T, water is represented with W, and cliffs\n";
cout << "are represented with C. Also, your characters are represented by the first\n";
cout << "letter of their class. \n";
cout << "\nPress enter to continue\n";
cin.get();
beginGame(height);
string line;
char map[height][43];
int curLine;
ifstream mapFile;
/* I begin by opening my file and then determining what line I am on. If I am in the first 2 lines, then I display
the first 2 lines of my text file. If not then I am pulling a random line from the text file.
*/
for (int I =0; I < height; I++)
{
mapFile.open("Map.txt");
if (I == 0 )
{
}
else if ( I == 1)
{
//ignores the first line to get the second one
getline(mapFile, line);
}
else
{
// gets random number and verifies it is within the files boundaries
curLine = (rand() % 33);
while (curLine == 0 || curLine == 1)
{
curLine = rand() % 33;
}
// skips us to the random line in the file
for (int X = 0; X < curLine; X++)
{
getline(mapFile, line);
}
}
mapFile.getline (map[I],42);
// by closing and reopening we start back at the beginning of the file
mapFile.close();
}
// displays the map this is where I am having problems
for (int I =0; I < height; I++)
{
for (int X =0; X < 43; X++)
{
cout << map[I][X];
}
cout << "\n";
}
return 0;
}
|