Classes...?

I have a class for player health and battle. Then i have an integer for player health.

Heres My Code:

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
79
80
#include <time.h>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

class Player
{
    public:
        int Health;
};
class Magic
{
    public:
        int Raw;
        int Luck;
        int Power;
};
int main(int argc, char *argv[])
{
    srand ( time(NULL) );
    int Battle_Check = 1;
    char Battle_Fight [20];
    int Player_Turn = 1;
            
    Player Player_One;
    Player_One.Health = 100;
    
    Player Player_Two;
    Player_Two.Health = 100;
    
    Magic User;
    User.Luck = rand() % 10;
    
    Magic Fireball;    
    Fireball.Raw = 20;
    Fireball.Power = Fireball.Raw + User.Luck;
    
    Magic Icestorm;
    Icestorm.Raw = 23;
    Icestorm.Power = Icestorm.Raw + User.Luck;
    
    Magic Lightbeam;
    Lightbeam.Raw = 56;
    Lightbeam.Power = Lightbeam.Raw + User.Luck;
    
    cout<<"The Power of Fireball is " << Fireball.Power << endl;
    cout<<"The Power of Icestorm is " << Icestorm.Power << endl;
    cout<<"The Power of Lightbeam is " << Lightbeam.Power << endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"Let The Battle Begin"<<endl;
    while (Battle_Check = 1) {
          if (Player_Turn == 1) {
              cout<<"woo\n";
              cin.getline(Battle_Fight,20);
              if (Battle_Fight == "fireball") {
                  cout<<"woo\n";
                  cout<<"Damage done: " << Fireball.Power << " ..." << endl;
                  Player_One.Health = Player_One.Health - Fireball.Power;
                  cout << Player_One.Health << endl;
                  Player_Turn = 2;
                  }
          }
          if (Player_Turn == 2) {
              cout<<"woo\n";
              if (Battle_Fight == "fireball") {
                  cout<<"woo\n";
                  cout<<"Damage done: " << Fireball.Power << " ..." << endl;
                  Player_Two.Health = Player_Two.Health - Fireball.Power;
                  Player_Turn = 1;
                  }
          }
    }
          
    
    system("PAUSE");
    return (EXIT_SUCCESS);
}


ps:...

I have the woo's to see which if statement it gets to..
I changed my woo's to woo and woo2. This showed me that its is not takeing the second if statement. Whats wrong with it?
This: if (Battle_Fight == "fireball") {
You're comparing two addresses here and they can never be equal.
Battle_Fight should be a string.
k, know when i enter a word intwo the cin>>Battle_Fight. How do i clear that word.
Battle_Fight.clear();
nvermind. I got it. I just put another cin under player two.. Now, on my random number. I have a "Luck" factor. I try to generate a random number, call it luck and add it to my damage numbor. Then I subtract that number from the health.

But I am only generating a random number once or something. Cause it always does the same damage. I think its possibley the fact that i do all the math before saying fireball. Am i right. If so, how can I create a way to make all the battle math, a run().
What i mean is :

i have int main()

can i make another one called int Battle()
and just have all the math in it. Then the only problem would be figuring out how to run it, and close it....

help...........


Here's my new code:

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
79
#include <time.h>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

class Player
{
    public:
        int Health;
};
class Magic
{
    public:
        int Raw;
        int Luck;
        int Power;
};
int main(int argc, char *argv[])
{
    srand ( time(NULL) );
    int Battle_Check = 1;
    string Battle_Fight;
    int Player_Turn = 1;
            
    Player Player_One;
    Player_One.Health = 100;
    
    Player Player_Two;
    Player_Two.Health = 100;
    
    Magic User;
    User.Luck = rand() % 10;
    
    Magic Fireball;    
    Fireball.Raw = 20;
    Fireball.Power = Fireball.Raw + User.Luck;
    
    Magic Icestorm;
    Icestorm.Raw = 23;
    Icestorm.Power = Icestorm.Raw + User.Luck;
    
    Magic Lightbeam;
    Lightbeam.Raw = 56;
    Lightbeam.Power = Lightbeam.Raw + User.Luck;
    
    cout<<"The Power of Fireball is " << Fireball.Power << endl;
    cout<<"The Power of Icestorm is " << Icestorm.Power << endl;
    cout<<"The Power of Lightbeam is " << Lightbeam.Power << endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"Let The Battle Begin"<<endl;
    while (Battle_Check = 1) {
          if (Player_Turn == 1) {
              cin>>Battle_Fight;
              if (Battle_Fight == "fireball") {
                  cout<<"Damage done: " << Fireball.Power << " ..." << endl;
                  Player_One.Health = Player_One.Health - Fireball.Power;
                  cout << Player_One.Health << endl;
                  Player_Turn = 2;
                  }
          }
          if (Player_Turn == 2) {
              cin>>Battle_Fight;
              if (Battle_Fight == "fireball") {
                  cout<<"Damage done: " << Fireball.Power << " ..." << endl;
                  Player_Two.Health = Player_Two.Health - Fireball.Power;
                  cout << Player_Two.Health << endl;
                  Player_Turn = 1;
                  }
          }
    }
          
    
    system("PAUSE");
    return (EXIT_SUCCESS);
}
mkay, I got the random number working. I moved User.Luck = rand & Fireball.Power =
into the if statements.

Anyway, I would still like to know how to seperate these attacks. I know i could use def: in Python. What is its similar in c++?
Topic archived. No new replies allowed.