Problem "Glueing" terms

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>                                                             //#Includes begin
#include <windows.h>                                                            //#Includes end
#define mons(a,b) a ## b                                                        //Connect values directly together for choosing monster

HANDLE SymC = GetStdHandle(STD_OUTPUT_HANDLE);                                  //Enable windows text colors

//mINIT begin                                                                   <-[CLASS] mINIT begin
class mINIT
{
public:
 void ATT(int Sup)                                                              //Change main attack value
 {mATT = mATT + Sup;}                                                           //Value + set amount
 void DEF(int Sup)                                                              //Change main defense value
 {mDEF = mDEF + Sup;}                                                           //Value + set amount
 void ACC(int Sup)                                                              //Change main accuracy value
 {mACC = mACC + Sup;}                                                           //Value + set amount
 void SPD(int Sup)                                                              //Change main speed value
 {mSPD = mSPD + Sup;}                                                           //Value + set amount
 void INT(int Sup)                                                              //Change main intelligence value
 {mINT = mINT + Sup;}                                                           //Value + set amount
 void HP(int Sup)                                                               //Change main health points value
 {mHP = mHP + Sup;}                                                             //Value + set amount
 void MP(int Sup)                                                               //Change main mana/magic points value
 {mMP = mMP + Sup;}                                                             //Value + set amount
 void transform(int Sup)                                                        //Change type value (For monster transformations)
 {mTYPE = mTYPE + Sup;}                                                         //Value + set amount
 int mATT;                                                                      //1 Attack
 int mDEF;                                                                      //2 Defense
 int mACC;                                                                      //3 Accuracy
 int mSPD;                                                                      //4 Speed
 int mINT;                                                                      //5 Intelligence
 int mHP;                                                                       //6 Health Points
 int mMP;                                                                       //7 Mana/Magic Points
 int mACS;                                                                      //8 Access Number
 char mSYM;                                                                     //9 Symbol
 int mCOL;                                                                      //10 Color
 char mNAME[30];                                                                //11 Name
 int mTYPE;                                                                     //12 Type (0 Friendly, 1 Hostile, 2 Neutral, 3 Calm, 4+ Other)
};
//mINIT end                                                                     <-[CLASS] mINIT end

//Declaring Monsters begin                                                      <-Declaring Monsters begin (x = Finished, . = Not Finished)
mINIT m1 = {3, 4, 5, 5, 2, 8, 0, 1, 'g', 2,"Goblin", 2};                        //1 x Goblin g
mINIT m2 = {4, 4, 3, 5, 3, 10, 0, 2, 'o', 10, "Orc", 2};                        //2 x Orc o
mINIT m3 = {3, 3, 6, 5, 3, 6, 0, 3, 'g', 9, "Goblin Thrower", 2};               //3 x Goblin Thrower g
mINIT m4 = {4, 3, 6, 7, 4, 6, 0, 4, 'o', 2,"Orc Archer", 2};                    //4 x Orc Archer o
mINIT m5 = {5, 5, 2, 2, 1, 14, 0, 5, 'T', 7, "Troll", 2};                       //5 x Troll T
mINIT m6 = {2, 2, 4, 6, 3, 5, 0, 6, 'g', 6, "Hobgoblin", 2};                    //6 x Hobgoblin g
mINIT m7 = {5, 4, 5, 4, 5, 8, 0, 7, 'h', 9,"Dwarf", 2};                         //7 x Dwarf h
mINIT m8 = {4, 3, 4, 5, 5, 8, 0, 8, 'h', 14, "Dwarf Child", 2};                 //8 x Dwarf Child h
mINIT m9 = {4, 4, 4, 6, 1, 8, 0, 9, 'd', 7, "Jackal", 2};                       //9 x Jackal d
mINIT m10 = {5, 4, 4, 5, 4, 12, 0, 10, 'k', 10,"Kobold", 2};                    //10 x Kobold k
mINIT m11 = {3, 3, 6, 6, 4, 8, 0, 11, 'k', 2, "Kobold Archer", 2};              //11 x Kobold Archer k
mINIT m12 = {2, 2, 3, 6, 1, 5, 0, 4, 'r', 6, "Rat", 2};                         //12 x Rat r
/*mINIT mGoblin = {3, 4, 5, 5, 2, 8, 0, 1, 'g', 2,"Goblin"};                    //13 . Goblin g
mINIT mOrc = {4, 4, 3, 5, 3, 10, 0, 2, 'o', 10, "Orc"};                         //14 . Orc o
mINIT mGoblinThrower = {3, 3, 6, 5, 3, 6, 0, 3, 'g', 9, "Goblin Thrower"};      //15 . Goblin Thrower g
mINIT mOrcArcher = {4, 3, 6, 7, 4, 6, 0, 4, 'o', 2,"Orc Archer"};               //16 . Orc Archer o
mINIT mTroll = {5, 5, 2, 2, 1, 14, 0, 5, 'T', 7, "Troll"};                      //17 . Troll T
mINIT mHobgoblin = {2, 2, 4, 6, 3, 5, 0, 6, 'g', 6, "Hobgoblin"};               //18 . Hobgoblin g
mINIT mDwarf = {5, 4, 5, 4, 5, 8, 0, 7, 'h', 9,"Dwarf"};                        //19 . Dwarf h
mINIT mDwarfChild = {4, 3, 4, 5, 5, 8, 0, 8, 'h', 14, "Dwarf Child"};           //20 . Dwarf Child h
mINIT mJackal = {4, 4, 4, 6, 1, 8, 0, 9, 'd', 7, "Jackal"};                     //21 . Jackal d
mINIT mKobold = {5, 4, 4, 5, 4, 12, 0, 10, 'k', 10,"Kobold"};                   //22 . Kobold k
mINIT mKoboldArcher = {3, 3, 6, 6, 4, 8, 0, 11, 'k', 2, "Kobold Archer"};       //23 . Kobold Archer k
mINIT mRat = {2, 2, 3, 6, 1, 5, 0, 4, 'r', 6, "Rat"};                           //24 . Rat r*/
//Declaring Monsters end                                                        <-Declaring Monsters end

int main()
{
 using namespace std;
 for(int num = 1; num < 13; num++)
 {
  cout << mons(m,(num)).mNAME << endl;
 }
 cin.get();
}
 

On the line that says cout << mons(m,(num)).mNAME << endl;, the mons is a preprocessor directive that should put "m" and the value num directly together to find a monster... But when i run, it says "'m' is undeclared", and when i try mons(m,num), then it just says "mnum" is undeclared... How do i make it stick a value in a spot??? And by the way im commenting on almost every line so when i need to skim through my code, i can just quickly skim through the comments to tell where im at.
Last edited on
remove parentheses from num.
Or use arrays...
I already tried... Then the compiler just says "mnum" is undeclared... Im just testing this preprocessor directive, I havent used it before...
Last edited on
The preprocessor won't unroll the loop for you.

Thus mons(m,num) will be turned into mnum and that's that.

You can't do what you want just with the preprocessor.
Last edited on
Is there any other way I can put these together?? The preprocessor would help so much when choosing random monsters:

choose = rand() % 13
cout << mons(m,(num)).mNAME << endl;

Im trying to aim for something that works like that.
Like Bazzy said, use arrays.

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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

struct Monster
{
    string name;
    int hp;
    int att;
    int def;

    Monster(){}

    Monster(string name_, int hp_, int att_, int def_):
        name(name_),hp(hp_),att(att_),def(def_){}
};

Monster monster_table[]=
{
    Monster("Goblin",10,2,1),
    Monster("Orc",25,5,3),
    Monster("Dragon",100,20,15)
};

int main()
{
    srand(time(0));

    Monster monster;

    for (int i=0; i<5; i++)
    {
        cout << "This time you fight against a(n)... ";

        monster=monster_table[rand()%3];
        cout << monster.name << endl;
    }

    cout << "\nhit enter to quit...";
    cin.get();
    return 0;
}
Instead of having a variables named m1, m2, m3, etc., use something like a std::map<unsigned int, mINIT>.
Figured it out now.
Topic archived. No new replies allowed.