#include <conio.h>
#include <graphics.h> /*This doesn't work in Visual C++, I get no such file or directory */
#include <iostream.h>
const int RAD = 5;
const int MAX = 10;
const int DIST = (RAD+MAX);
const int LEFT = 0;
const int TOP = 0;
const int RIGHT = 639;
const int BOTTOM = 479;
enum hdir {hSTOP=0, hRIGHT, hLEFT};
enum vdir {vSTOP=0,vDOWN,vUP};
class molecule
{
private:
int xCo,yCo;
int oldx, oldy;
int speed;
hdir horz;
vdir vert;
COLORS color;
public:
molecule (int x, int y, int s, hdir h, vdir v, COLORS c)
{
xCo=x;
yCo=y;
speed=s;
horz=h;
vert=v;
color=c;
}
void erase();
void calculate();
void draw();
};
void molecule::erase()
{
setcolor(DARKGRAY);
circle(oldx,oldy, RAD);
setfillstyle(SOLID_FILL,BLACK);
floodfill(oldx,oldy,DARKGRAY);
setcolor(BLACK);
circle (oldx,oldy,RAD);
}
void molecule::calculate()
{
oldx=xCo;
oldy=yCo;
switch(horz)
{
case hSTOP: /* no move */
break;
case hRIGHT:
xCo+=speed;
break;
case hLEFT:
xCo-=speed;
break;
}
if (xCo<=LEFT+DIST)
{
horz=hRIGHT;
}
else if (xCo>=RIGHT - DIST)
{
horz = hLEFT;
}
switch(vert)
{
case vSTOP: /* no move */
break;
case vDOWN:
{
yCo+-speed;
}
break;
case vUP:
{
yCo-= speed;
}
break;
}
if (yCo<=TOP+DIST)
{
vert=vDOWN;
}
else if (yCo>=BOTTOM-DIST)
{
vert=vUP;
}
}
void molecule:
raw()
{
setcolor(color);
circle(xCo,yCo,RAD);
setfillstyle (SOLID_FILL,color);
floodfill(xCo,yCo,color);
}
void main()
{
int driver,mode;
driver = DETECT;
initgraph(&driver,&mode,"\\bc5\\bgi");
molecule m1(100,120,2,hRIGHT,vUP,BLUE);
molecule m2(150,220,2,hLEFT,vUP,GREEN);
molecule m3(200,140,37,hRIGHT,vDOWN,CYAN);
molecule m4(250,240,.5,hLEFT,vDOWN,RED);
molecule m5(300,160,15,hRIGHT,vUP,MAGENTA);
molecule m6(350,260,3,hLEFT,vUP,LIGHTGREEN);
molecule m7(150,350,8,hLEFT,vSTOP,LIGHTGRAY);
molecule m8(150,350,4,hRIGHT,vUP,BROWN);
molecule m9(370,60,15,hRIGHT,vUP,MAGENTA);
molecule m10(30,280,3,hLEFT,vUP,LIGHTGREEN);
molecule m11(350,320,8,hLEFT,vSTOP,LIGHTGRAY);
rectangle(LEFT,TOP,RIGHT,BOTTOM);
while(!kbhit())
{
m1.calculate();m1.erase(); m1.draw();
m2.calculate();m2.erase(); m2.draw();
m3.calculate();m3.erase(); m3.draw();
m4.calculate();m4.erase(); m4.draw();
m5.calculate();m5.erase(); m5.draw();
m6.calculate();m6.erase(); m6.draw();
m7.calculate();m7.erase(); m7.draw();
m8.calculate();m8.erase(); m8.draw();
m9.calculate();m9.erase(); m9.draw();
m10.calculate();m10.erase(); m10.draw();
m11.calculate();m11.erase(); m11.draw();
}closegraph();
}
This is everything, it works in Borland but not in Visual C++ 6.0 and it's driving me crazy. I'm a major newbie when it comes to C++ so spare the high tech talk. Please help me out on this one.
-Failing programmer
#include <graphics.h> /*This doesn't work in Visual C++, I get no such file or directory */
#include <iostream.h>
const int RAD = 5;
const int MAX = 10;
const int DIST = (RAD+MAX);
const int LEFT = 0;
const int TOP = 0;
const int RIGHT = 639;
const int BOTTOM = 479;
enum hdir {hSTOP=0, hRIGHT, hLEFT};
enum vdir {vSTOP=0,vDOWN,vUP};
class molecule
{
private:
int xCo,yCo;
int oldx, oldy;
int speed;
hdir horz;
vdir vert;
COLORS color;
public:
molecule (int x, int y, int s, hdir h, vdir v, COLORS c)
{
xCo=x;
yCo=y;
speed=s;
horz=h;
vert=v;
color=c;
}
void erase();
void calculate();
void draw();
};
void molecule::erase()
{
setcolor(DARKGRAY);
circle(oldx,oldy, RAD);
setfillstyle(SOLID_FILL,BLACK);
floodfill(oldx,oldy,DARKGRAY);
setcolor(BLACK);
circle (oldx,oldy,RAD);
}
void molecule::calculate()
{
oldx=xCo;
oldy=yCo;
switch(horz)
{
case hSTOP: /* no move */
break;
case hRIGHT:
xCo+=speed;
break;
case hLEFT:
xCo-=speed;
break;
}
if (xCo<=LEFT+DIST)
{
horz=hRIGHT;
}
else if (xCo>=RIGHT - DIST)
{
horz = hLEFT;
}
switch(vert)
{
case vSTOP: /* no move */
break;
case vDOWN:
{
yCo+-speed;
}
break;
case vUP:
{
yCo-= speed;
}
break;
}
if (yCo<=TOP+DIST)
{
vert=vDOWN;
}
else if (yCo>=BOTTOM-DIST)
{
vert=vUP;
}
}
void molecule:
{
setcolor(color);
circle(xCo,yCo,RAD);
setfillstyle (SOLID_FILL,color);
floodfill(xCo,yCo,color);
}
void main()
{
int driver,mode;
driver = DETECT;
initgraph(&driver,&mode,"\\bc5\\bgi");
molecule m1(100,120,2,hRIGHT,vUP,BLUE);
molecule m2(150,220,2,hLEFT,vUP,GREEN);
molecule m3(200,140,37,hRIGHT,vDOWN,CYAN);
molecule m4(250,240,.5,hLEFT,vDOWN,RED);
molecule m5(300,160,15,hRIGHT,vUP,MAGENTA);
molecule m6(350,260,3,hLEFT,vUP,LIGHTGREEN);
molecule m7(150,350,8,hLEFT,vSTOP,LIGHTGRAY);
molecule m8(150,350,4,hRIGHT,vUP,BROWN);
molecule m9(370,60,15,hRIGHT,vUP,MAGENTA);
molecule m10(30,280,3,hLEFT,vUP,LIGHTGREEN);
molecule m11(350,320,8,hLEFT,vSTOP,LIGHTGRAY);
rectangle(LEFT,TOP,RIGHT,BOTTOM);
while(!kbhit())
{
m1.calculate();m1.erase(); m1.draw();
m2.calculate();m2.erase(); m2.draw();
m3.calculate();m3.erase(); m3.draw();
m4.calculate();m4.erase(); m4.draw();
m5.calculate();m5.erase(); m5.draw();
m6.calculate();m6.erase(); m6.draw();
m7.calculate();m7.erase(); m7.draw();
m8.calculate();m8.erase(); m8.draw();
m9.calculate();m9.erase(); m9.draw();
m10.calculate();m10.erase(); m10.draw();
m11.calculate();m11.erase(); m11.draw();
}closegraph();
}
This is everything, it works in Borland but not in Visual C++ 6.0 and it's driving me crazy. I'm a major newbie when it comes to C++ so spare the high tech talk. Please help me out on this one.
-Failing programmer
