hi, i have created a game using TC++.. a very basic game.. and i want to use the same in VC++

could anyone please help me with this. i shall be grateful to you guys..

i think that there may be a problem with using the various header files in tc++ which are not supported in vc++.

please take a look at the program.

am using very basic functions and am only moving a ball in four different directions..

could you please tell me how to convert the same into vc++?

or how do u create a moving ball in different directions..

thank you

#include <stdio.h>
#include <stdlib.h>
#include "graphics.h"
#include "dos.h"
#include "conio.h"

#define ARROW_SIZE 10

void draw_arrow(int x, int y);
void erase(int i, int j);
void uwin();
int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
   void *arrow, *arrow1, *arrow2, *arrow3;
   void *a[4];
   int x, y, maxx,maxy;
   char s[4];
   unsigned int size, size1;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "m:\\tc\\bgi");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      exit(1); /* terminate with an error code */
   }
const char up='w';
const char dw='s';
const char ls='a';
const char rs='d';
   maxy=getmaxy();
   maxx = getmaxx();
   x = 320;
   y = 240;



   /* draw the image to be grabbed */
  // draw_arrow(x, y);
   circle(x,y,20);

      /* calculate the size of the image */
   size = imagesize(x-20, y-20, x+20, y+20);
   randomize();

   /* allocate memory to hold the image */
   arrow = malloc(size);
    getimage(x-20,y-20, x+20, y+20, arrow);
       int okay=1;
    int i,j;
    while(okay==1)
    {
     i=rand()%580;
     j=rand()%460;
     okay=0;
     if( ( (i+60)>300) && (i<340) )
     okay=1;
     if( ( (j+20)>220) && (j<260) )
     okay=1;
    }


    rectangle(i,j,i+60,j+20);

    outtextxy(( i+i+60)/2,(j+j+20)/2,"GOAL");


    s[0]='U';
    s[1]='D';
    s[2]='L';
    s[3]='R';
//   outtextxy(x,y,"U");

    char ch;
   /* repeat until a key is pressed */
   while (1)
   {
      ch=getch();
      /* erase old image */
      erase(x,y);
      putimage(x-20, y-20, arrow, XOR_PUT);

     if(ch==up)
      {
       if(y-60<0)
       {
	 if(x<320)
	 {
	  x+=40;
	  outtextxy(x,y,"R");
	 }
	 else
	 {
	  x-=40;
	  outtextxy(x,y,"L");
	 }

       }
       else
       {
	y -=40;
	outtextxy(x,y,"U");
      }
     }

      if(ch==dw)
      {
	if(y+60>maxy)
	{
	 if(x<320)
	 {
	  x+=40;
	  outtextxy(x,y,"R");
	 }
	 else
	 {
	  x-=40;
	  outtextxy(x,y,"L");
	 }
	}
      else
      {
       y += 40;
       outtextxy(x,y,"D");
      }
     }
      if(ch==ls)
      {
       if(x-60<0)
       {
	if(y<240)
	{
	 y+=40;
	 outtextxy(x,y,"D");
	}
	else
	{
	 y-=40;
	 outtextxy(x,y,"U");
	}
       }
       else
       {
	x -= 40;
	outtextxy(x,y,"L");
       }
      }
      if(ch==rs)
      {
	if(x+60>maxx)
	{
	 if(y<240)
	 {
	  y+=40;
	  outtextxy(x,y,"D");
	 }
	 else
	 {
	  y-=40;
	  outtextxy(x,y,"U");
	 }
	}
	else
	{
	 x += 40;
	 outtextxy(x,y,"R");
	}
      }
      if(ch=='q')
      exit(1);

      /* plot new image */
      putimage(x-20, y-20, arrow, XOR_PUT);

      int col=0;

      if( x+20>i && x-20<i+60 )
      col++;

      if( y+20>j && y-20<j+20 )

      col++;

      if(col==2)
      uwin();


      delay(100);
   }

   /* clean up */
   free(arrow);
   closegraph();
   return 0;
}
 void erase(int i, int j)
 {
 int a=i;


 for(;a<i+8;a++)
  {

   for(int b=j;b<j+8;b++)
   {
    putpixel(a,b,BLACK);

    }
  }
 }
void uwin()
  {
      int sz=0;
      char* score1="Winner!";
      char msg[20];
      sprintf(msg, "%s", score1);
      for(int i=0 ;i<5 ;i++)
	{
		sz++;
		cleardevice();
		setcolor(i+2);
		settextstyle(0,0,sz);
		outtextxy(100,100,msg);

	}
     delay(400);
     exit(0);

}

You're using the infamous <conio.h>, which is specific to Borland compilers. To port it to VC++, you'll have to either of the following:

1) Find a Visual C++ port for conio.h. I don't know if one exists.
2) Use the Windows Console functions, which I believe is used by conio internally. You can find a beginner's tutorial here.

I'd also suggest you switch to another compiler. I think Turbo C++ has not been updated for at least a decade.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.