i have a problem with my notebook, its a toshiba, the video card is intel and i have windows...vista and xp, but i`ve been usin code blocks since 5 or 6 moths ago, programin' in C, everything was great...but...i have a teacher that ask us to make something in "graphic mode" and i found that with borland is possible to do that, then i learned how to configure CB to use the borland compiler...but i have a problem, the driver from borland isnt supported under any of my windows, so i think that the problem is with the video card...anyway...how can i make this code with gcc?...or with borland...?....always on CB...?
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<dos.h>
/// FUNCION DE LA SOLUCION LOGICA DE LOS MOVIMIENTOS ///
void Hanoi( int numDiscos, char origen, char auxiliar, char destino )
{
if( numDiscos==1 )
cout << origen << " --> " << destino << endl;
else
{
Hanoi( numDiscos-1, origen, destino, auxiliar );
cout << origen << " --> " << destino << endl;
Hanoi( numDiscos-1, auxiliar, origen, destino );
}
}
///// FUNCION DE GRAFICACION INICIAL DE LOS DISCOS /////
void grafini(int Num)
{
for(int i=1; i<=Num ; i++)
{
setcolor(i);
circle(160,350,15 + i*15);
}
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
}
///// FUNCION DE GRAFICACION FINAL DE LOS DISCOS /////
void graffin(int Num)
{
for(int i=1; i<=Num ; i++)
{
setcolor(i);
circle(480,350,15 + i*15);
}
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
}
///// FUNCION DE ANIMACION DE MOVIMIENTOS DE LOS DISCOS ////
void grafimov(int Numd,char origen, char destino)
{
switch (origen)
{
case 'A':
switch(destino)
{
case 'B':
for( double t=0.00; t<1.00; t=t+0.01 )
{
setcolor(0);
circle(160 +160*t,350-230*t, 15+Numd*15);
setcolor(Numd);
circle(160 +160*(t+0.01),350-230*(t+0.01),15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(160 +160*t,350-230*t, 15+Numd*15);
setcolor(Numd);
circle(160 +160,350-230, 15+Numd*15);
break;
case 'C':
for(t=0.00; t<1.00; t= t+0.01 )
{
setcolor(0);
circle(160 + 320*t,350, 15+Numd*15);
setcolor(Numd);
circle(160 +320*(t+0.01),350,15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(160 +320*t,350, 15+Numd*15);
setcolor(Numd);
circle(160 +320,350, 15+Numd*15);
break;
}
break;
case 'B':
switch(destino)
{
case 'A':
for(double t=0.00; t<1.00; t= t+0.01 )
{
setcolor(0);
circle(320 -160*t,120+230*t, 15+Numd*15);
setcolor(Numd);
circle(320 -160*(t+0.01),120+230*(t+0.01),15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(320 -160*t,120+230*t, 15+Numd*15);
setcolor(Numd);
circle(320 -160,120+230, 15+Numd*15);
break;
case 'C':
for( t=0.00; t<1.00; t= t+0.01 )
{
setcolor(0);
circle(320 + 160*t,120+230*t, 15+Numd*15);
setcolor(Numd);
circle(320 +160*(t+0.01),120+230*(t+0.01),15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(320 + 160*t,120+230*t, 15+Numd*15);
setcolor(Numd);
circle(320 + 160,120+230, 15+Numd*15);
break;
}
break;
case 'C':
switch(destino)
{
case 'B':
for(double t=0.00; t<1.00; t= t+0.01 )
{
setcolor(0);
circle(480 -160*t,350-230*t, 15+Numd*15);
setcolor(Numd);
circle(480 -160*(t+0.01),350-230*(t+0.01),15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(480 -160*t,350-230*t, 15+Numd*15);
setcolor(Numd);
circle(480 -160,350-230, 15+Numd*15);
break;
case 'A':
for( t=0.00; t<1.00; t= t+0.01 )
{
setcolor(0);
circle(480 - 320*t,350, 15+Numd*15);
setcolor(Numd);
circle(480 -320*(t+0.01),350,15+Numd*15);
setcolor(4);
outtextxy(155,345,"A");
outtextxy(315,115,"B");
outtextxy(475,345,"C");
delay(50);
}
setcolor(0);
circle(480 - 320*t,350, 15+Numd*15);
setcolor(Numd);
circle(480 - 320,350, 15+Numd*15);
break;
}
break;
}
}
///// FUNCION ANIMADORA DE LA SOLUCION COMPLETA ////
void Hanoigraf( int numDiscos, char origen, char auxiliar, char destino )
{
if( numDiscos==1 )
grafimov(numDiscos, origen, destino);
else
{
Hanoigraf( numDiscos-1, origen, destino, auxiliar );
grafimov(numDiscos,origen,destino);
Hanoigraf( numDiscos-1, auxiliar, origen, destino );
}
}
///// FUNCION PRINCIPAL ////
void main()
{
int NumDiscos;
cout << "Cuantos discos : ";
cin >> NumDiscos;
Hanoi( NumDiscos, 'A', 'B', 'C');
cout<<"YA TERMINE "<<endl;
cout<<"presione una tecla para continuar"<<endl;
getch();
/****** iniciacion del modo grafico ****/
int driver=DETECT,mode,resgraf;
initgraph(&driver,&mode,"c:\\tc\\bgi");
resgraf=graphresult();
if(resgraf!=grOk)
{
cout<<"Ha ocurrido un error en la inicializacion"<<endl;
cout<<"Presione una tecla para regresar al modo texto"<<endl;
getch();
exit(1);
}
grafini(NumDiscos);
Hanoigraf(NumDiscos,'A','B','C');
clearviewport();
graffin(NumDiscos);
outtextxy(170,445,"EL PROGRAMA DE ANIMACION HANOI TERMINO");
outtextxy(200,455,"Presione una tecla para continuar");
getch();
closegraph();
exit(1);
}