text based game trouble!

Im trying to make it so that when the battle() function is called on enemy.dummy, its .attack id displayed.help!

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

// GLOBAL VARIABLES
string charname;

//ENEMY CLASS
class enemy
{
public:
    int attack;   
    int defense;  
    int luck;   
    int speed;
    int hp;
    int energy;
};


//BATTLE FUNCTION

void battle(class enemy);
void battle(class enemy)
{
    cout << enemy.attack; 
    
}
//DISPLAY FUNCTION
void display(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo);
void display(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo){
    cout<<"attack: "<< navatk <<endl;
    cout<<"defense: "<< navdef <<endl;
    cout<<"speed: "<< navspd <<endl;
    cout<<"health points: "<< navhpo <<endl;
    cout<<"luck: "<< navluk <<endl;
    cout<<"energy points: "<< navepo <<endl;
};
//INTRO FUNCTION
int main();
int main(){
    
    cout<<"what's your name again?"<<endl; 
    cin>>charname; 
    cout<<"hello, "<<charname<<endl;
    sleep(2);
    cout<<"welcome to the pentagon"<<endl;
    sleep(1);
    cout<<"year: 4056 C.E." << endl;
    sleep(1);
    cout<<"you have been nominated to control a 'navigator.' a digital fighting warrior that we use to fight the rebellion."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"what's this? you've never heard of the rebellion before?"<<endl;
    sleep(1);
    cout<<"the year was 2015, when the citizens of the united states of america rose up against the government. little did they know, the governmet had installed a top-secret project called 'SEVEN' (or s.ecretly e.liminate v.iolent e.lectronic n.ews) into the world wide web . they used this successfully to break up riots by intercepting internet-bound messages. soon after, the rebellion's top scientists figured out the programs weak-spots, and created viruses 'bugs' to destroy said program."<<endl;
    sleep(12);
    cout<<"that's where you come in." << endl;
    sleep(1);
    cout<<"we've created an elite squad of web 'navigators' to destroy any viruses we encounter." <<endl;
    sleep(1);
    cout<<"you will be tasked with controlling one of these 'navigators' to end the rebellion once and for all."<<endl;
    sleep(1);
    cout<<"let me show you them"<<endl;
    choice:
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"bladenav: a well balanced navigator that can wield a multitude of de-bugging weapons"<<endl;
    cout<<"arrownav: a speed-oriented navigator that can attack stealthily from far range"<<endl;    
    cout<<"fistsnav: an attack-heavy navigator with low speed but with a variety of high-power weapons"<<endl;
    cout<<"shellnav: an extremely high defense navigator with low speed and attack "<<endl;
    cout<<"golemnav: a high attack, high defense navigator with low speed, and a narrow range of attacks "<< endl;
    cout<<"flamenav: a navigator with flame-based attacks with relatively large luck"<<endl;
    cout<<"aqueonav: a navigator with aqua-based attacks with relatively large luck"<<endl;    
    cout<<"plantnav: a navigator with plant-based attacks with relatively large luck"<<endl;
    cout<<"psychnav: a high hit points navigator with indirect attacking abilities"<<endl;
    cout<<"chicknav: a navigator with terrible stats all around and no redeeming qualities whatsoever except for it's 100% luck stat."<<endl;
    sleep(3);
    cout<<"you may choose one and only one to control. pick wisely"<<endl;
    string navchoice; 
    cin>> navchoice;
//STAT SETTING
    int navatk;
    int navdef;
    int navspd;
    int navhpo;
    int navluk;
    int navepo;

    if (navchoice == "bladenav")
    {
         navatk = 50;
         navdef = 50;
         navspd = 50;
         navhpo = 100;
         navluk = 10;
         navepo = 40;
    };
    if (navchoice =="arrownav")
    {
         navatk = 55;
         navdef = 30;
         navspd = 65;
         navhpo = 100;
         navluk = 10;
         navepo = 40;
    };
    if (navchoice =="fistsnav")
    {
         navatk = 80;
         navdef = 55;
         navspd = 10;
         navhpo = 115;
         navluk = 10;
         navepo = 30;
    };  
    if (navchoice =="shellnav")
    {
         navatk = 25;
         navdef = 80;
         navspd = 25;
         navhpo = 120;
         navluk = 10; 
         navepo = 40;
    };
    if (navchoice =="golemnav")
    {
         navatk = 70;
         navdef = 70;
         navspd = 10;
         navhpo = 100;
         navluk = 10;
         navepo = 40;
    };   
    if (navchoice =="flamenav")
    {
         navatk = 50;
         navdef = 50;
         navspd = 40;
         navhpo = 100;
         navluk = 15;
         navepo = 45;
    };  
    if (navchoice =="aqueonav")
    {
         navatk = 50;
         navdef = 50;
         navspd = 40;
         navhpo = 100;
         navluk = 15;
         navepo = 45;
    };
    if (navchoice =="plantnav")
    {
         navatk = 50;
         navdef = 50;
         navspd = 40;
         navhpo = 100;
         navluk = 15;
         navepo = 45;    
    };
    if (navchoice =="psychnav")
    {
         navatk = 20;
         navdef = 30;
         navspd = 30;
         navhpo = 150;
         navluk = 10;
         navepo = 50;
    };
    if (navchoice =="chicknav")
    {
         navatk = 20;
         navdef = 20;
         navspd = 20;
         navhpo = 100;
         navluk = 100;
         navepo = 40;
    };
    sleep(1);
    display(navatk, navdef, navspd, navhpo, navluk, navepo);
    sleep(1);
    cout<<"is this you're final selection, "<< charname <<"?"<<endl;
    string yesno;
    cin >> yesno; 
    if(yesno == "no"){
        cout<< "let me show you them again" << endl;
        goto choice;
    }
    cout<<"now that you've chosen your navigator, you should probably learn how to use it."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"when you find an enemy 'bug', battle mode is initiated."<<endl;
    sleep(1);
    cout<<" ______________________________________________________"<<endl;
    cout<<"|ATTACK| WEAPONS | ITEMS | FLEE | CHECK STATS | DEFEND |"<<endl;
    cout<<"|______|_________|_______|______|_____________|________|"<<endl;  
    sleep(1);
    cout<<"then you select an option. choosing 'attack' attacks the opponent. The damage you deal is equal to the weapon's power added to your attack, then subtracted by the enemy's defense. 'weapons' accesses your de-bugging arsenal, 'items' allows you to view and use your one-use items, 'check stats' checks both your and the enemy's health points and stats, and 'defend' doubles your defense for the next turn, but takes up a turn. activating 'flee' will end the encounter unless your speed is lower than the 'bug's'."<<endl;
    sleep(10);
    cout<<"then, after your turn is over, your oppenent will either attack or defend."<< endl;
    pause:
    sleep(5);
    cout<< "all good?" <<endl;
    cin >> yesno;
    if (yesno == "no"){
        goto pause;
    };
    cout<<"in that case, INITIATE BATTLE SIMULATION GO!"<<endl;
    enemy dummy;
    dummy.attack = 0; 
    dummy.defense = 0; 
    dummy.speed = 0; 
    dummy.luck = 0; 
    dummy.hp = 0;
    dummy.energy= 0;
    battle(dummy);
    return 0;
}
1. enemy is a type. In the declaration and definition you should have something similar to what you have on line 217.

2. Please get rid of those gotos and use functions instead. Please? :/

-Albatross
By the time you read this I had already gotten rid of the gotos, but what do you mean in the declaration and definition?


void battle(???)

what do I put in there?
Something similar to what you put on line 217: an object declaration.

-Albatross
what if i want the function to pass any one of my 'enemy' class and not just enemy dummy!?
Well, the function already takes any enemy. You're just specifically passing it dummy in that instance. You could rename it to anything, and it would work all the same. You could create two, and call the function twice while passing either. It would work all the same.
I made some corrections to your code so it runs.
I also broke up most things into functions and added several member functions to your enemy class. Note the effect on the length of the main() function. It is now just 10 lines long!

Some things for you to consider...
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <windows.h>// for the Sleep() function (not sleep)
using namespace std;

// GLOBAL VARIABLES
string charname;

//ENEMY CLASS
class enemy
{
public:
    int attack;
    int defense;
    int luck;
    int speed;
    int hp;
    int energy;

    // class member functions
    void INIT(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo);
    void display();
    void battle();
};

// global helper functions
void intro();
string choice(enemy & e );
void stage1();
string allGood();

//*** main ***
int main(){
    enemy dummy;// an instance of enemy to work with

    intro();
    while( choice(dummy) == "no") cout<< "let me show you them again" << endl;// replaces goto scheme
    stage1();
    while( allGood() == "no");// replaces goto scheme
    cout<<"in that case, INITIATE BATTLE SIMULATION GO!"<<endl;
    dummy.battle();

    return 0;
}// end of main()

// definitions of enemy class member functions
void enemy::INIT(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo)
{
    attack = navatk;
    defense = navdef;
    speed = navspd;
    hp = navhpo;
    luck = navluk;
    energy = navepo;
}

void enemy::display()
{
    cout<<"attack: "<< attack <<endl;
    cout<<"defense: "<< defense <<endl;
    cout<<"speed: "<< speed <<endl;
    cout<<"health points: "<< hp <<endl;
    cout<<"luck: "<< luck <<endl;
    cout<<"energy points: "<< energy <<endl;
}

void enemy::battle()
{
    cout << attack;
}

// definitions of helper functions
void intro()
{
    cout<<"what's your name again?"<<endl;
    cin>>charname;
    cout<<"hello, "<<charname<<endl;
    Sleep(2);
    cout<<"welcome to the pentagon"<<endl;
    Sleep(1);
    cout<<"year: 4056 C.E." << endl;
    Sleep(1);
    cout<<"you have been nominated to control a 'navigator.' a digital fighting warrior that we use to fight the rebellion."<<endl;
    Sleep(1);
    cout<<"..."<<endl;
    Sleep(1);
    cout<<"what's this? you've never heard of the rebellion before?"<<endl;
    Sleep(1);
    cout<<"the year was 2015, when the citizens of the united states of america rose up against the government. little did they know, the governmet had installed a top-secret project called 'SEVEN' (or s.ecretly e.liminate v.iolent e.lectronic n.ews) into the world wide web . they used this successfully to break up riots by intercepting internet-bound messages. soon after, the rebellion's top scientists figured out the programs weak-spots, and created viruses 'bugs' to destroy said program."<<endl;
    Sleep(12);
    cout<<"that's where you come in." << endl;
    Sleep(1);
    cout<<"we've created an elite squad of web 'navigators' to destroy any viruses we encounter." <<endl;
    Sleep(1);
    cout<<"you will be tasked with controlling one of these 'navigators' to end the rebellion once and for all."<<endl;
    Sleep(1);
    cout<<"let me show you them"<<endl;
}

string choice(enemy & e )
{
    Sleep(1);
    cout<<"..."<<endl;
    Sleep(1);
    cout<<"bladenav: a well balanced navigator that can wield a multitude of de-bugging weapons"<<endl;
    cout<<"arrownav: a speed-oriented navigator that can attack stealthily from far range"<<endl;
    cout<<"fistsnav: an attack-heavy navigator with low speed but with a variety of high-power weapons"<<endl;
    cout<<"shellnav: an extremely high defense navigator with low speed and attack "<<endl;
    cout<<"golemnav: a high attack, high defense navigator with low speed, and a narrow range of attacks "<< endl;
    cout<<"flamenav: a navigator with flame-based attacks with relatively large luck"<<endl;
    cout<<"aqueonav: a navigator with aqua-based attacks with relatively large luck"<<endl;
    cout<<"plantnav: a navigator with plant-based attacks with relatively large luck"<<endl;
    cout<<"psychnav: a high hit points navigator with indirect attacking abilities"<<endl;
    cout<<"chicknav: a navigator with terrible stats all around and no redeeming qualities whatsoever except for it's 100% luck stat."<<endl;
    Sleep(3);
    cout<<"you may choose one and only one to control. pick wisely"<<endl;
    string navchoice;
    cin>> navchoice;
//STAT SETTING
    if (navchoice == "bladenav") e.INIT(50, 50, 50, 100, 10, 40);
    else if (navchoice =="arrownav") e.INIT(55, 30, 65, 100, 10, 40);
    else if (navchoice =="fistsnav") e.INIT(80, 55, 10, 115, 10, 30);
    else if (navchoice =="shellnav") e.INIT(25, 80, 25, 120, 10, 40);
    else if (navchoice =="golemnav") e.INIT(70, 70, 10, 100, 10, 40);
    else if (navchoice =="flamenav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="aqueonav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="plantnav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="psychnav") e.INIT(20, 30, 30, 150, 10, 50);
    else if (navchoice =="chicknav") e.INIT(20, 20, 20, 100, 100, 40);
    Sleep(1);
    e.display();
    Sleep(1);
    cout<<"is this you're final selection, "<< charname <<"?"<<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}

void stage1()
{
    cout<<"now that you've chosen your navigator, you should probably learn how to use it."<<endl;
    Sleep(1);
    cout<<"..."<<endl;
    Sleep(1);
    cout<<"when you find an enemy 'bug', battle mode is initiated."<<endl;
    Sleep(1);
    cout<<" ______________________________________________________"<<endl;
    cout<<"|ATTACK| WEAPONS | ITEMS | FLEE | CHECK STATS | DEFEND |"<<endl;
    cout<<"|______|_________|_______|______|_____________|________|"<<endl;
    Sleep(1);
    cout<<"then you select an option. choosing 'attack' attacks the opponent. The damage you deal is equal to the weapon's power added to your attack, then subtracted by the enemy's defense. 'weapons' accesses your de-bugging arsenal, 'items' allows you to view and use your one-use items, 'check stats' checks both your and the enemy's health points and stats, and 'defend' doubles your defense for the next turn, but takes up a turn. activating 'flee' will end the encounter unless your speed is lower than the 'bug's'."<<endl;
    Sleep(10);
    cout<<"then, after your turn is over, your oppenent will either attack or defend."<< endl;
}

string allGood()
{
    Sleep(5);
    cout<< "all good?" <<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}
thanks fun2code, but you turned the navs into enemies, which i hadn't wanted. They're the choices for the main character.
Sorry. I couldn't distinguish between them. From a programming perspective, each is a collection of 6 integer values. It seemed logical to use the class you created to represent each.

EDIT: Perhaps until there is some difference between them you could use an enemy instance for each? Semi-appropriate as each is an enemy of the other?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(){
    enemy nav;

    intro();
    while( choice(nav) == "no") cout<< "let me show you them again" << endl;// replaces goto scheme
    stage1();
    while( allGood() == "no");// replaces goto scheme
    cout<<"in that case, INITIATE BATTLE SIMULATION GO!"<<endl;
    enemy dummy;
    dummy.INIT(0,0,0,0,0,0);
    dummy.battle();

    return 0;
}// end of main() 
Last edited on
thanks! heres what i've peiced together so far.


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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//PROBOSOFT INC.



#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

// GLOBAL VARIABLES
string charname;

//ENEMY CLASS
class nav
{
public:
    int attack;
    int defense;
    int luck;
    int speed;
    int hp;
    int energy;
    
    // class member functions
    void INIT(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo);
    void display();
    void battle();
};

// global helper functions
void intro();
string choice(nav & e );
void stage1();
string allGood();

//*** main ***
int main(){
    nav dummy;// an instance of enemy to work with
    
    intro();
    while( choice(dummy) == "no") cout<< "let me show you them again" << endl;// replaces goto scheme
    stage1();
    while( allGood() == "no");// replaces goto scheme
    cout<<"in that case, INITIATE BATTLE SIMULATION GO!"<<endl;
    dummy.battle();
    
    return 0;
}// end of main()

// definitions of enemy class member functions
void nav::INIT(int navatk, int navdef, int navspd, int navhpo, int navluk, int navepo)
{
    attack = navatk;
    defense = navdef;
    speed = navspd;
    hp = navhpo;
    luck = navluk;
    energy = navepo;
}

void nav::display()
{
    cout<<"attack: "<< attack <<endl;
    cout<<"defense: "<< defense <<endl;
    cout<<"speed: "<< speed <<endl;
    cout<<"health points: "<< hp <<endl;
    cout<<"luck: "<< luck <<endl;
    cout<<"energy points: "<< energy <<endl;
}

// definitions of helper functions
void intro()
{
    cout<<"what's your name again?"<<endl;
    cin>>charname;
    cout<<"hello, "<<charname<<endl;
    sleep(2);
    cout<<"welcome to the pentagon"<<endl;
    sleep(1);
    cout<<"year: 4056 C.E." << endl;
    sleep(1);
    cout<<"you have been nominated to control a 'navigator.' a digital fighting warrior that we use to fight the rebellion."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"what's this? you've never heard of the rebellion before?"<<endl;
    sleep(1);
    cout<<"the year was 2015, when the citizens of the united states of america rose up against the government. little did they know, the governmet had installed a top-secret project called 'SEVEN' (or s.ecretly e.liminate v.iolent e.lectronic n.ews) into the world wide web . they used this successfully to break up riots by intercepting internet-bound messages. soon after, the rebellion's top scientists figured out the programs weak-spots, and created viruses 'bugs' to destroy said program."<<endl;
    sleep(12);
    cout<<"that's where you come in." << endl;
    sleep(1);
    cout<<"we've created an elite squad of web 'navigators' to destroy any viruses we encounter." <<endl;
    sleep(1);
    cout<<"you will be tasked with controlling one of these 'navigators' to end the rebellion once and for all."<<endl;
    sleep(1);
    cout<<"let me show you them"<<endl;
}

string choice(nav & e )
{
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"bladenav: a well balanced navigator that can wield a multitude of de-bugging weapons"<<endl;
    cout<<"arrownav: a speed-oriented navigator that can attack stealthily from far range"<<endl;
    cout<<"fistsnav: an attack-heavy navigator with low speed but with a variety of high-power weapons"<<endl;
    cout<<"shellnav: an extremely high defense navigator with low speed and attack "<<endl;
    cout<<"golemnav: a high attack, high defense navigator with low speed, and a narrow range of attacks "<< endl;
    cout<<"flamenav: a navigator with flame-based attacks with relatively large luck"<<endl;
    cout<<"aqueonav: a navigator with aqua-based attacks with relatively large luck"<<endl;
    cout<<"plantnav: a navigator with plant-based attacks with relatively large luck"<<endl;
    cout<<"psychnav: a high hit points navigator with indirect attacking abilities"<<endl;
    cout<<"chicknav: a navigator with terrible stats all around and no redeeming qualities whatsoever except for it's 100% luck stat."<<endl;
    sleep(3);
    cout<<"you may choose one and only one to control. pick wisely"<<endl;
    string navchoice;
    cin>> navchoice;
    //STAT SETTING
    if (navchoice == "bladenav") e.INIT(50, 50, 50, 100, 10, 40);
    else if (navchoice =="arrownav") e.INIT(55, 30, 65, 100, 10, 40);
    else if (navchoice =="fistsnav") e.INIT(80, 55, 10, 115, 10, 30);
    else if (navchoice =="shellnav") e.INIT(25, 80, 25, 120, 10, 40);
    else if (navchoice =="golemnav") e.INIT(70, 70, 10, 100, 10, 40);
    else if (navchoice =="flamenav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="aqueonav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="plantnav") e.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="psychnav") e.INIT(20, 30, 30, 150, 10, 50);
    else if (navchoice =="chicknav") e.INIT(20, 20, 20, 100, 100, 40);
    sleep(1);
    e.display();
    sleep(1);
    cout<<"is this you're final selection, "<< charname <<"?"<<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}

void stage1()
{
    cout<<"now that you've chosen your navigator, you should probably learn how to use it."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"when you find an enemy 'bug', battle mode is initiated."<<endl;
    sleep(1);
    cout<<" ______________________________________________________"<<endl;
    cout<<"|ATTACK| WEAPONS | ITEMS | FLEE | CHECK STATS | DEFEND |"<<endl;
    cout<<"|______|_________|_______|______|_____________|________|"<<endl;
    sleep(1);
    cout<<"then you select an option. choosing 'attack' attacks the opponent. The damage you deal is equal to the weapon's power added to your attack, then subtracted by the enemy's defense. 'weapons' accesses your de-bugging arsenal, 'items' allows you to view and use your one-use items, 'check stats' checks both your and the enemy's health points and stats, and 'defend' doubles your defense for the next turn, but takes up a turn. activating 'flee' will end the encounter unless your speed is lower than the 'bug's'."<<endl;
    sleep(10);
    cout<<"then, after your turn is over, your oppenent will either attack or defend."<< endl;
}

string allGood()
{
    sleep(5);
    cout<< "all good?" <<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}
That's great. Is it working as desired?
I see you renamed the class from enemy to nav.

Where are you getting the sleep() function? I changed it to Sleep() because it wouldn't compile on my (windows) system. Evidently it works on your system.
He might be using linux it is lowercase sleep for linux and uppercase on windows.
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//PROBOSOFT INC.



#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

// GLOBAL VARIABLES
string charname;

//NAV CLASS
class nav
{
public:
    int attack;
    int defense;
    int speed;
    int luck;
    int hp;
    int energy;
    
    //CLASS MEMBER FUNCTIONS
    void INIT(int attack, int defense, int speed, int hp, int luck, int energy);
    
    void display();
};

//BUG CLASS
class bug
{
public:
    int attack;
    int defense;
    int luck;
    int speed;
    int hp;
    int energy;
    
    //CLASS MEMBER FUNCTIONS
    void INIT(int bugatk, int bugdef, int bugspd, int bughpo, int bugluk, int bugepo);
    void display();
};

//GLOBAL HELPER FUNCTIONS
void intro();
string choice(nav & n );
void stage1();
string allGood();

//MAIN FUNCTION
int main(){
    nav dummynav;// an instance of enemy to work with
    
    intro();
    while( choice(dummynav) == "no") cout<< "let me show you them again" << endl;// replaces goto scheme
    stage1();
    while( allGood() == "no");// replaces goto scheme
    cout<<"in that case, INITIATE BATTLE SIMULATION GO!"<<endl;

    
    return 0;
}// end of main()

void nav::display()
{
    cout<<"attack: "<< attack <<endl;
    cout<<"defense: "<< defense <<endl;
    cout<<"speed: "<< speed <<endl;
    cout<<"health points: "<< hp <<endl;
    cout<<"luck: "<< luck <<endl;
    cout<<"energy points: "<< energy <<endl;
}

void intro()
{
    cout<<"what's your name again?"<<endl;
    cin>>charname;
    cout<<"hello, "<<charname<<endl;
    sleep(2);
    cout<<"welcome to the pentagon"<<endl;
    sleep(1);
    cout<<"year: 4056 C.E." << endl;
    sleep(1);
    cout<<"you have been nominated to control a 'navigator.' a digital fighting warrior that we use to fight the rebellion."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"what's this? you've never heard of the rebellion before?"<<endl;
    sleep(1);
    cout<<"the year was 2015, when the citizens of the united states of america rose up against the government. little did they know, the governmet had installed a top-secret project called 'SEVEN' (or s.ecretly e.liminate v.iolent e.lectronic n.ews) into the world wide web . they used this successfully to break up riots by intercepting internet-bound messages. soon after, the rebellion's top scientists figured out the programs weak-spots, and created viruses 'bugs' to destroy said program."<<endl;
    sleep(12);
    cout<<"that's where you come in." << endl;
    sleep(1);
    cout<<"we've created an elite squad of web 'navigators' to destroy any viruses we encounter." <<endl;
    sleep(1);
    cout<<"you will be tasked with controlling one of these 'navigators' to end the rebellion once and for all."<<endl;
    sleep(1);
    cout<<"let me show you them"<<endl;
}

string choice(nav & n )
{
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"bladenav: a well balanced navigator that can wield a multitude of de-bugging weapons"<<endl;
    cout<<"arrownav: a speed-oriented navigator that can attack stealthily from far range"<<endl;
    cout<<"fistsnav: an attack-heavy navigator with low speed but with a variety of high-power weapons"<<endl;
    cout<<"shellnav: an extremely high defense navigator with low speed and attack "<<endl;
    cout<<"golemnav: a high attack, high defense navigator with low speed, and a narrow range of attacks "<< endl;
    cout<<"flamenav: a navigator with flame-based attacks with relatively large luck"<<endl;
    cout<<"aqueonav: a navigator with aqua-based attacks with relatively large luck"<<endl;
    cout<<"plantnav: a navigator with plant-based attacks with relatively large luck"<<endl;
    cout<<"psychnav: a high hit points navigator with indirect attacking abilities"<<endl;
    cout<<"chicknav: a navigator with terrible stats all around and no redeeming qualities whatsoever except for it's 100% luck stat."<<endl;
    sleep(3);
    cout<<"you may choose one and only one to control. pick wisely"<<endl;
    string navchoice;
    cin>> navchoice;
    //NAV STAT SETTING
    if (navchoice == "bladenav") n.INIT(50, 50, 50, 100, 10, 40);
    else if (navchoice =="arrownav") n.INIT(55, 30, 65, 100, 10, 40);
    else if (navchoice =="fistsnav") n.INIT(80, 55, 10, 115, 10, 30);
    else if (navchoice =="shellnav") n.INIT(25, 80, 25, 120, 10, 40);
    else if (navchoice =="golemnav") n.INIT(70, 70, 10, 100, 10, 40);
    else if (navchoice =="flamenav") n.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="aqueonav") n.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="plantnav") n.INIT(50, 50, 40, 100, 15, 45);
    else if (navchoice =="psychnav") n.INIT(20, 30, 30, 150, 10, 50);
    else if (navchoice =="chicknav") n.INIT(20, 20, 20, 100, 100, 40);
    sleep(1);
    n.display();
    sleep(1);
    cout<<"is this you're final selection, "<< charname <<"?"<<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}

void stage1()
{
    cout<<"now that you've chosen your navigator, you should probably learn how to use it."<<endl;
    sleep(1);
    cout<<"..."<<endl;
    sleep(1);
    cout<<"when you find an enemy 'bug', battle mode is initiated."<<endl;
    sleep(1);
    cout<<" ______________________________________________________"<<endl;
    cout<<"|ATTACK| WEAPONS | ITEMS | FLEE | CHECK STATS | DEFEND |"<<endl;
    cout<<"|______|_________|_______|______|_____________|________|"<<endl;
    sleep(1);
    cout<<"then you select an option. choosing 'attack' attacks the opponent. The damage you deal is equal to the weapon's power added to your attack, then subtracted by the enemy's defense. 'weapons' accesses your de-bugging arsenal, 'items' allows you to view and use your one-use items, 'check stats' checks both your and the enemy's health points and stats, and 'defend' doubles your defense for the next turn, but takes up a turn. activating 'flee' will end the encounter unless your speed is lower than the 'bug's'."<<endl;
    sleep(10);
    cout<<"then, after your turn is over, your oppenent will either attack or defend."<< endl;
}

string allGood()
{
    sleep(5);
    cout<< "all good?" <<endl;
    string yesno;
    cin >> yesno;
    return yesno;
}
the code above won't compile, and when I try to, it gives me this...

Undefined symbols for architecture x86_64:
"nav::INIT(int, int, int, int, int, int)", referenced from:
choice(nav&) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Yikes!
*correction

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class bug
{
public:
    int bugatk;
    int bugdef;
    int bugluk;
    int bugspd;
    int bughpo;
    int bugepo;
    
    //CLASS MEMBER FUNCTIONS
    void INIT(int bugatk, int bugdef, int bugspd, int bughpo, int bugluk, int bugepo);
    void display();
};

but it still wont compile...
You left out the function definitions for nav::INIT(), bug::display() and bug::INIT(). Compare to the earlier code where definitions are provided for all 3 member functions of the enemy class.

Try to put a bit more time into learning the language before jumping into making a game. This effort will payoff very well.

@giblit. Thank. I figured sleep() is probably a unix thing. A little research turned that up. I was puzzled as to why no #include is needed for it.
Last edited on
thanks, fun2code.

I'm teaching myself by making a game and learning along the way, and I'm also reading a C++ book bit by bit.

Topic archived. No new replies allowed.