Originally Posted by
Elysia
Again, this is what you should not do.
You should type your code and compile regularly. This helps you find your errors quicker and more efficiently.
Typing the whole thing on paper first will only mean double work and more errors.
I highly recommend that you rely on the compiler. Type your code into your editor/IDE and compile it when you've finished a part.
Oh okay,ill trust your word,thanks for the advice,i took your advice on trying to be ambitous and stuff and using class i wrote this fight simulator, its not very advanced but, it's a start, i made it to reinforce the skills i've learned when i was reading up on classes:
This is my main.cpp file:
Code:
#include <iostream>
#include "main.h"
using namespace std;
int main()
{
string x;
int useratt,oppatt,newhp1,newhp2,rand1,rand2;
Character Goodguy;
Goodguy.Job;
Goodguy.HP;
Goodguy.Attack;
Goodguy.Skill;
Goodguy.Speed;
Goodguy.Defence;
Character Badguy;
Badguy.Job;
Badguy.HP;
Badguy.Attack;
Badguy.Skill;
Badguy.Speed;
Badguy.Defence;
cout << "What class are you?" << endl;
cin >> Goodguy.Job;
cout << "What class is your opponent?" << endl;
cin >> Badguy.Job;
cout << "It's a " << Goodguy.Job << " VS. " << Badguy.Job << "!" << endl;
cout << "How attack does your character have?" << endl;
cin >> Goodguy.Attack;
cout << "How much Defence do you have?" << endl;
cin >> Goodguy.Defence;
cout << "How much HP do you have?" << endl;
cin >> Goodguy.HP;
cout << "How much HP does your opponent have?" << endl;
cin >> Badguy.HP;
cout << "How much Defence does your opponent have?" << endl;
cin >> Badguy.Defence;
cout << "Do you want to attack?" << endl;
cin >> x;
rand1 = rand() % 10 + 1;
rand2 = rand() % 10 + 1;
if(rand1 == rand2)
{
Goodguy.Attack = Goodguy.critical(Goodguy.Attack);
}
if(x == "Yes" || x == "yes")
{
useratt=Goodguy.attack(Goodguy.Attack,Badguy.HP,Badguy.Defence);
if(useratt < Badguy.HP)
{
newhp2=Badguy.HP-useratt;
if(rand1 == rand2)
{
cout << "Critical hit" << endl;
Goodguy.Attack = Goodguy.critical(Goodguy.Attack);
}
cout << "Your opponent lost " << newhp2 << " hp" << endl;
Badguy.HP=useratt;
}
else if(useratt == Badguy.HP)
{
cout << "Your opponent still has " << Badguy.HP << " hp" << endl;
Badguy.HP=Badguy.HP;
}
}
cout << endl;
cout << "Your opponent's turn to attack!" << endl;
cout << "How much attack does your opponent have?" << endl;
cin >> Badguy.Attack;
cout << "Attack: " << Badguy.Attack << endl;
oppatt=Badguy.attack(Badguy.Attack,Goodguy.HP,Goodguy.Defence);
if(oppatt < Goodguy.HP)
{
newhp2=Goodguy.HP-oppatt;
cout << "You lost " << newhp2 << " hp" << endl;
Goodguy.HP=oppatt;
}
else if(oppatt == Goodguy.HP)
{
cout << "You lost no HP" << endl;
cout << "You still have " << oppatt << " hp now" << endl;
}
cout << endl;
cout << endl;
cout << "You have has " << Goodguy.HP << " hp now" << endl;
cout << "Your opponent has " << Badguy.HP << " hp now" << endl;
return 0;
}
Now this is my header file for main.cpp:
Code:
using namespace std;
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
class Character
{
public:
string Job;
int Attack;
int HP;
int Skill;
int Speed;
int Defence;
int attack(int x,int y,int z) // x=user attack,y=opp hp,z=opp def
{
int result;
int diff;
result=(x-z);
if(result < 0 || result == 0)
{
cout << "You did no damage" << endl;
return y;
}
else
diff=y-result;
return diff;
}
int critical(int x)
{
int result;
result= x * 3;
return result;
}
};
#endif // MAIN_H_INCLUDED
What do you think???