Class combat, Please Help!

I am trying to make a combat system. I have a function called checkSpace() that checks whether or not there's a wall, monster, etc. Here's my checkSpace()
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
void checkSpace()
{
    CFurbolg furbolg;
    if (buffer[y][x] == 'I')
    {
        spaceWall = true;
    }
    if (z==1 && p==1)
    {
        if (x==7 && y==9)
        {
            z=2;
            explored1 = true;
        }
    }
    if (z==2 && p==1)
    {
        if (explored2 == false)
        {
            storyline3print();
            explored2 = true;
        }
        if (x==4 && y==0)
        {
            z = 1;
        }
        if (x==9 && y==7)
        {
            p = 2;
        }
        if (x==9 && y==6)
        {
            p = 2;
        }
        if (x==9 && y==5)
        {
            p = 2;
        }
    }
    if (z==2 && p==2)
    {
        if (explored3 == false)
        {
            storyline4print();
            explored3=true;
        }
        if (buffer[x][y] == buffer[furbolg.gety()][furbolg.getx()])
        {
            combat();
        }
    }
}


I have two classes, CFurbolg:
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
class CFurbolg
{
    private:
    int x;
    int y;
    int health, mana, stamina, damage;

    public:
    CFurbolg()
    {}

    CFurbolg(int _y, int _x)
    {
        setx(_x);
        sety(_y);
    }

    ~CFurbolg()
    {}

    void setx(int _x)// The following will set the Furbolg's position on the map
    {
        x = _x;
    }

    void sety(int _y)
    {
        y = _y;
    }

    void set_values(int a, int b, int c, int d)
    {
        health=a;
        mana=b;
        stamina=c;
        damage=d;
    }

    int gety()
    {
        return y;
    }

    int getx()
    {
        return x;
    }

    int gethealth()
    {
        return health;
    }

    int getmana()
    {
        return mana;
    }

    int getstamina()
    {
        return stamina;
    }

    int getdamage()
    {
        return damage;
    }

    void moveFurbolg(int _y, int _x)
    {
        if (z==2 && p==2)
        {
            y = _y;
            x = _x;
        }
    }

    void sethealth(int a)
    {
        health=a;
    }
};


And CPlayer:
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
class CPlayer
{
    private:
    int health, mana, stamina, damage;

    public:
    CPlayer()
    {}

    ~CPlayer()
    {}

    void set_values()
    {
        health=100;
        mana=100;
        stamina=100;
        getInfo();
        if (race == "High Elf")
        {
            mana = mana + 100;
            health = health - 25;
            stamina = stamina - 75;
        }
        if (race == "Centaur")
        {
            mana = mana - 75;
            health = health + 50;
            stamina = stamina + 25;
        }
        if (race == "Crystalline")
        {
            mana = mana - 25;
            health = health + 50;
            stamina = stamina - 25;
        }
        if (race == "Human")
        {
            mana = mana;
            health = health;
            stamina = stamina;
        }
        if (race == "Ent")
        {
            mana = mana + 50;
            health = health - 25;
            stamina = stamina - 25;
        }
    }

    void set_damage()
    {
        getInfo();
        if (specialization == "Mage")
        {
            damage = 10;
        }
        if (specialization == "Warrior")
        {
            damage = 20;
        }
        if (specialization == "Archer")
        {
            damage = 15;
        }
        if (specialization == "Rogue")
        {
            damage = 17;
        }
        if (specialization == "Priest")
        {
            damage = 10;
        }
    }

    int gethealth()
    {
        return health;
    }

    int getmana()
    {
        return mana;
    }

    int getstamina()
    {
        return stamina;
    }

    int getdamage()
    {
        return damage;
    }

    void sethealth(int a)
    {
        health=a;
    }
};


and then I have commands which is a constant loop so tht the Player can enter input at any time
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
void commands()
{
    while (d==1)
    {
        getline(cin, input);

        if (input == "w")
        {
            y=y-1;
            checkSpace();
            if (spaceWall == true)
            {
                y=y+1;
                wallprint();
                spaceWall = false;
            }
            else
            {
                printToBuffer();
                printPlayer();
                printBuffer();
            }
        }
        else if (input == "s")
        {
            y=y+1;
            checkSpace();
            if (spaceWall == true)
            {
                y=y-1;
                wallprint();
                spaceWall = false;
            }
            else
            {
                printToBuffer();
                printPlayer();
                printBuffer();
            }
        }
        else if (input == "a")
        {
            x=x-1;
            checkSpace();
            if (spaceWall == true)
            {
                x=x+1;
                wallprint();
                spaceWall = false;
            }
            else
            {
                printToBuffer();
                printPlayer();
                printBuffer();
            }
        }
        else if (input == "d")
        {
            x=x+1;
            checkSpace();
            if (spaceWall == true)
            {
                x=x-1;
                wallprint();
                spaceWall = false;
            }
            else
            {
                printToBuffer();
                printPlayer();
                printBuffer();
            }
        }
        else if (input == "investigate")
        {
            investigate();
        }
        else if (input == "map" or input == "m")
        {
            printBuffer();
        }
        else if (input == "quit")
        {
            d=0;
        }
        else if (input == "attack")
        {
            if (fight = true)
            {
                hit();
            }
        }
    }
}


I have a function called combat which starts a fight and every 2 seconds he furbolg deals damage to the player. The problem is is that as soon as the player enters the map, it intiates a fight even though the furbolg is on the other side of the room. It also won't allow the player to attack. If anyone could help I would be very thankful
You mention the function called combat could be causing problems but I don't see that function posted here right now..?

The only problem I see while scrolling through is in your commands function.
1
2
3
4
5
6
7
else if (input == "attack")
{
      if (fight = true)
      {
           hit();
      }
}


It should be if(fight == true)
Topic archived. No new replies allowed.