Brick game in graphics.h

Hi. First of all I want to apologize for my bad English.
I want to do a C++ brick game using graphics.h library.
I am getting 2 errors saying that 2 of my functions were not decleared in this scope.

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
227
228
 //This is main.cpp
#include <iostream>
#include <graphics.h>
#include "cerc.h"
#include "playerBrick.h"
#include "bricks.h"
#include "ball.h"
#include <cmath>
using namespace std;

int main()
{
    cout<<"Press esc to close the graph!";
    char ch;
    //delay(3000);
    initwindow(1500,700);
    //cerc co;
    ball ballObj;
    playerBrick bo;
    bricks bObj;
    while(1)
    {
        ch=getch();
        if((int)ch==97)
            bo.moveLeft();
        else
            if((int)ch==100)
                bo.moveRight();
            else
                if((int)ch==27)
                {
                    closegraph();
                    cout<<"Graph closed!";
                }
    }
    return 0;
}
//playerBrick.h
#ifndef PLAYERBRICK_H
#define PLAYERBRICK_H


class playerBrick
{
    friend class ball;
    public:
        playerBrick();
        void moveLeft();
        void moveRight();
        void clean();
        bool exist(double x1, double y1, double x2, double y2);
    private:
        double x1,y1,x2,y2;
};

#endif // PLAYERBRICK_H
//playerBrrick.cpp
#include "playerBrick.h"
#include <iostream>
#include <graphics.h>

using namespace std;

playerBrick::playerBrick()
{
    setcolor(GREEN);
    rectangle(500,600,1000,700);
    x1=500;
    y1=600;
    x2=1000;
    y2=700;
}

void playerBrick::moveLeft()
{
    if(exist(x1-10,y1,x2-10,y2)==1)
    {
        clean();
        x1-=10;
        x2-=10;
        setcolor(GREEN);
        rectangle(x1,y1,x2,y2);
    }
}

void playerBrick::moveRight()
{
    if(exist(x1+10,y1,x2+10,y2)==1)
    {
        clean();
        x1+=10;
        x2+=10;
        setcolor(GREEN);
        rectangle(x1,y1,x2,y2);
    }
}

void playerBrick::clean()
{
    setcolor(BLACK);
    rectangle(x1,y1,x2,y2);
}

bool playerBrick::exist(double x1, double y1, double x2, double y2)
{
    if(x1>=10&&x2<=1370)
        return 1;
    else
        return 0;
}
//bricks.h
#ifndef BRICKS_H
#define BRICKS_H


class bricks
{
    public:
        bricks();
        bool exist();
        void clean(double x1, double y1, double x2, double y2);
    private:
        int a[7];
        double x1,y1,x2,y2;

};

#endif // BRICKS_H
//bricks.cpp
#include "bricks.h"
#include <iostream>
#include <graphics.h>

bricks::bricks()
{
    setcolor(RED);
    rectangle(20,50,220,150);
    rectangle(230,50,430,150);
    rectangle(440,50,640,150);
    rectangle(650,50,850,150);
    rectangle(860,50,1060,150);
    rectangle(1070,50,1270,150);
    for(int i=1; i<=6; i++)
        a[i]=1;
}

bool bricks::exist()
{

}

void bricks::clean(double x1, double y1, double x2, double y2)
{
    setcolor(BLACK);
    rectangle(x1,y1,x2,y2);
}
//ball.h
#ifndef BALL_H
#define BALL_H


class ball
{
    public:
        ball();
        bool exist(double x, double y);
        int hit(double x, double y);
        void clean(double x, double y, double r);
    private:
        double x,y,r;
        double atmX,atmY;
};

#endif // BALL_H
//ball.cpp
#include "ball.h"
#include <iostream>
#include <graphics.h>

ball::ball()
{
    setcolor(GREEN);
    x=625;
    y=350;
    r=50;
    circle(x,y,r);
}

bool ball::exist(double x, double y)
{
    if(x>=60&&x<=1440&&y>=60&&y<=640)
        return 1;
    else
        return 0;
}

int hit(double x, double y, double p, double q)// x si y pozitia actuala, p si q coordonatele tintei
{
    double biggerRatio;
    double r1,r2;
    r1=(p-x)/10;
    r2=(q-y)/10;
    if(r1>r2)
        biggerRatio=r1;
    else
        biggerRatio=r2;
    r1=r1/biggerRatio;
    r2=r2/biggerRatio;
    double i,j;
    for(i=x, j=y; i<=p, j<=q; i+=r1,j+=r2)// left hand operand of comma has no //effect
    {
        if(exist(x+r1,y+r2)==1)// error:  'exist' was not decleared in this //scope
            return 0;
        else
        {
            clean(x,y,50);// same for clean
            setcolor(GREEN);
            circle(x,y,50);
        }
    }
}

void ball::clean(double x, double y, double r)
{
    setcolor(BLACK);
    circle(x,y,r);
}


I get just these 2 errors and that warning. I don't know why.
The purpose of that hit function is to hit from a point of(x,y) in another (p,q);
like this i want to aim a random point at beggining and use this function to shoot there.
I need just to fix this problem and make 2 more functions:
1. to redirect the ball when it hits the wall
2. to destroy the bricks;
Topic archived. No new replies allowed.