int main()
{
begin:
string name;
string surname;
int ehp = 100;
int edefense = 0;
int eattack = 1;
int positionx = 5;
int positiony = 1;
int epositionx = 5;
int epositiony = 10;
int hp = 100;
int defense = 0;
int attack = 1;
int money = 100;
int maxmana = 100;
int mana = 100;
bool male;
string answer;
int badgood = 0;
int luck;
cout << "enter your warriors first name" << endl;
cin >> name;
cout << "now their lastname" << endl;
cin >> surname;
system ("CLS");
cout << "long intro unable to fit into forum submission"<< endl;
system ("pause");
system ("CLS");
cout << "to begin this game you will be asked some basic questions, please answer all multiple choice questions in capitol letters" << endl;
cout << "are they a male?" << endl;
cin >> answer;
if (answer == "yes")
{
male = "1";
attack = attack + 1;
}
if (answer == "no")
{
male = "0";
defense = defense + 1;
}
system("CLS");
cout << "your enemy falls at your feet and offers his life" << endl;
cout << "A. you kill him with your trusty sword" << endl;
cout << "B. you make him your slave" << endl;
cout << "C. you free him" << endl;
if (answer == "C")
{
badgood = 10;
}
system("CLS");
cout << "you are stopped on the street by a mysterious hooded figure and asked for money, what do you do?" << endl;
cout << "A. you give it to them" << endl;
cout << "B. you say no" << endl;
cout << "C. you give it to them asking for something in return" << endl;
cin >> answer;
if (answer == "B")
{
badgood = badgood - 1;
}
if (answer == "A")
{
badgood = badgood + 3;
}
luck = rand() % 100 + 1;
if (answer == "C" && luck > 50 )
{
cout << endl << "they cast a strange spell on you making you feel powerfull";
defense = defense + 1;
attack = attack + 1;
hp = hp + 1;
maxmana = maxmana + 1;
mana = mana + 1;
}
system ("CLS");
cout << "thank you for answering these questions in future versions, there will be more questions to better determine your character" << endl ;
system("pause");
system("CLS");
cout << "please look in your manual for controls" << endl ;
system("pause");
system("CLS");
cout << "you hear Cordata VIII begin the games and you remember who you must kill" << endl ;
Possibly the longest line of code I've seen on these forums at 1805 characters. The program begs for the use of for-loops.
The weird characters are most likely the result of trying to access elements outside of the array arena[10][10], valid subscripts are in the range 0-9 and 0-9 so accessing arena[x][10] or arena[10][x] is an error.
Remember, that the left side of the arena, starts with 0, so to go left, you subtract 1 from your position, and add 1, to go right. Same with up and down. Top of screen is 0. If you're going south, or down, you add 1 and subtract 1, when going up.
The difference in execution time is trivial. But if you want to speed it up, treat each row as a character string, and output the whole line in one step.
1 2 3 4 5 6 7 8 9 10 11
// Define and fill the array
constint rows = 10;
constint cols = 10;
char arena [rows][cols+1]; // extra column for null terminator
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
arena[i][j] = '*'; // fill array with '*'
arena[i][cols] = 0; // Null Terminator
}
Output it like this:
1 2
for (int i=0; i<rows; i++)
cout << arena[i] << endl;
or like this:
1 2
for (int i=0; i<rows; i++)
puts(arena[i]);
You could even define the entire board as one long single-dimension array with newline characters and a single null terminator. Then the output reduces to a simple puts(arena);. The downside is you have to calculate the subscripts like this: arena[y*rowlength + x] where rowlength is the number of character per row. At that stage it starts to look like the basis for a class where the details are handled internally and the code which uses it becomes very simple.
execution is trivial in this type, but in my first post about diamond program before I learn about recursive function, execution time was very noticeable
going to try to compare the different outputs when I get home