8 Replies - 309 Views - Last Post: 09 February 2019 - 07:34 PM Rate Topic: -----

#1 Solemnghost   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-February 19

TO combine four different type of programs to make a single one

Posted 09 February 2019 - 03:20 AM

hi guys.
i am working on a project in turbo c++.
i have 4 codes.
snake game,digital clock,3d calculator,animation ball
all codes are working correctly,i need to combine these 4 to a single program.
so when i run it i dont need to go back on the program scrren .i want tht i run it a single time .
it ask me the choice what i want to do
1.game
2. clock.
3.calculate
4.animation
it take choice from me on output screen and if i press 1 i can play game come back
them animation and so on
i dont want to come back on programming screen again and again
can anyone suggest any ideas how to combine these 4.
thanks for reading the article.
here are the codes.
-snake game  code

#include<stdio.h>
#include<dos.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define TOP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
void score(int s=1)
{
	static unsigned long sc=0;
	window(70,22,78,23);
	if(s)
	{
		sc=sc+100;
		cprintf("      ");
		window(70,22,78,23);
		cprintf("%ld",sc);
	}
	else
		sc=0;
}
void status(char *s,int c=WHITE)
{
	window(70,23,78,25);
	textcolor(c);
	cprintf("%s",s);
	for(int x=strlen(s);x<7;x++)
	cprintf(" ");
	textcolor(WHITE);
}
void main()
{
	clrscr();
	_setcursortype(_NOCURSOR);
	textcolor(WHITE);
	cprintf("\n   ???????????????????????????????????????????????????????????????????????????  ");
	for(int i=0;i<17;i++)
	cprintf("   ?                                                                         ?  ");
	cprintf("   ???????????????????????????????????????????????????????????????????????????  ");
	cprintf("   ????????????????????????   Press 'x' to Exit            ???????????????????  ");
	cprintf("   ?  S N A K E  G A M E  ?   Press 'p' to Pause and Play  ? SCORE : 0       ?  ");
	cprintf("   ????????????????????????                                ? STATUS: Playing ?  ");
	cprintf("                                                           ???????????????????  ");
	int snkx[20],snky[20],d=LEFT,p=0,sz=6,restart=1;
	while(1)
	{
		if(restart)
		{
			for(i=0;i<6;i++)
			snkx[i]=30+i*2;
			for(i=6;i<20;i++)
			snkx[i]=0;
			for(i=0;i<20;i++)
			snky[i]=9;
			sz=6;
			p=0;
			d=LEFT;
			restart=0;
			score();
			window(6,3,76,19);
			for(i=0;i<610;i++)
			cprintf("  ");
		}
		int x,y;
		if(p!=1)
		{
			randomize();
			do{
						x=random(70)+6;
					}while(x%2==1);
					y=random(16)+3;
			p=1;
			window(x,y,x+1,y+1);
			textcolor(LIGHTGREEN);
			cprintf("%c",1);
			textcolor(WHITE);
		}
		while(!kbhit())
		{
			status("Playing",LIGHTGREEN);
			window(snkx[sz-1],snky[sz-1],snkx[sz-1]+2,snky[sz-1]+2);
			cprintf(" ");
			for(i=0;i<sz-1;i++)
			{
				window(snkx[i],snky[i],snkx[i]+1,snky[i]+1);
				cprintf("");
			}
			for(i=sz-1;i>=1;i--)
			{
				snkx[i]=snkx[i-1];
				snky[i]=snky[i-1];
			}
			switch(d)
			{
				case RIGHT : snkx[0]+=2; break;
				case LEFT  : snkx[0]-=2; break;
				case TOP   : snky[0]-=1; break;
				case DOWN  : snky[0]+=1;
			}
			delay(200);
			if(x==snkx[0] && y==snky[0])
			{
				int f=0;
				do{
					do{
						x=random(70)+6;
					}while(x%2==1);
					y=random(16)+3;
					for(i=0;i<sz;i++)
						if(snkx[i]==x && snky[i]==y)
							f=1;
				}while(f);
				p=1;
				window(x,y,x+1,y+1);
				textcolor(LIGHTGREEN);
				cprintf("%c",1);
				textcolor(WHITE);

				score();
				sz++;

				switch(d)
				{
					case RIGHT : snkx[sz-1]+=2;
								 snky[sz-1]=snky[sz-2];
								 break;
					case LEFT  : snkx[sz-1]-=2;
								 snky[sz-1]=snky[sz-2];
								 break;
					case TOP   : snky[sz-1]-=1;
								 snkx[sz-1]=snkx[sz-2];
								 break;
					case DOWN  : snky[sz-1]+=1;
								 snkx[sz-1]=snkx[sz-2];
				}
			}
			int sflag=0;
			for(i=0;i<sz-1;i++)
				if(snkx[sz-1]==snkx[i] && snky[sz-1]==snky[i])
				{
					sflag=1;
					break;
				}
			if(snkx[0]<5 || snkx[0]>76 || snky[0]<3 || snky[0]>19)
				sflag=1;
			if(sflag)
			{
				textcolor(LIGHTRED);
				for(i=1;i<sz;i++)
				{
					window(snkx[i],snky[i],snkx[i]+1,snky[i]+1);
					cprintf("");
				}
				status("Stoped",LIGHTRED);
				score(0);
				restart=1;
				break;
			}
		}
		char ch=getch();
		switch(tolower(ch))
		{
			case 'x' : return;
			case 'p' :
						status("Paused");
						getch();
						break;
			case 0 : {
						char chh=getch();
						switch(chh)
						{
							case 72 :{
									if(d==LEFT || d== RIGHT)
									d=TOP;
									} break;
							case 80 :{
									if(d==LEFT || d== RIGHT)
									d=DOWN;
									} break;
							case 75 :{
									if(d==TOP || d==DOWN)
									d=LEFT;
									} break;
							case 77 :{
									if(d==TOP || d==DOWN)
									d=RIGHT;
									}
						}
					} break;
		}
	}
}   // main




-digital clock
#include <stdio.h>
  #include <conio.h>
  #include <graphics.h>
  #include <time.h>
  #include <dos.h>
  #include <string.h>

  int main() {
        /* request auto detection */
        int gdriver = DETECT, gmode;
        int midx, midy, err;
        long mytime;
        char date[256];

        /* initialize graphic mode */
        initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
        err = graphresult();

        if (err != 0) {
                /* error occurred */
                printf("Graphics Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        /* mid positions in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* mid positions in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        while (!kbhit()) {
                /* clears graphic screen */
                cleardevice();

                /* get time in seconds */
                mytime = time(NULL);

                /* store the date and time in the given string */
                strcpy(date, ctime(&mytime));

                settextjustify(CENTER_TEXT, CENTER_TEXT);
                settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);

                /* locate the postion to write */
                moveto(midx, midy);

                /* print the date and time */
                outtext(date);

                /* sleep for a second */
                sleep(1);
        }

        getch();

        /* deallocate memory allocated for graphic screen */
        closegraph();
        return 0;
  }



-calculator
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<string.h>

union REGS in,out;

/* Global Variables */

char text[25][4]={"1","2","3","+","4","5","6","-","7","8","9","*","s^2","0","=","/","C"," "," ","E"};
int i,j,X,Y,pass,opr,Opr;
long int num=0,pnum=0,anum=0,total=0;

/* The following User-defined functions will be used in the program */

void CalculatorPics(); /* To draw calculator */
int CallMouse();       /* To call mouse */
int HideMouse();       /* To hide mouse */
int AddNum(int pass);  /* To input number */
int Operation(int opr);   /* To perform operations like additon,multiplication etc.*/
void Square();  /* To find square of a number */
void MousePosi(int *Xpos,int *Ypos,int *Click); /* To get the position of mouse and the left button pressed or not */
void Start();

/*****************************************/
/* Main Function */

void main()
{
int B;
int gd=DETECT,gm;
int x,y,button;
initgraph(&gd,&gm,"c://turboc3//bgi"/* Path of bgi graphics */);
CalculatorPics();
CallMouse();
while(1)/* Infinite Loop */
{
MousePosi(&x,&y,&button);
/*******************************/
X=283;
Y=123;
j=0;
do
{
i=0;
do
{
if((x>X-20 && x<X+27) && (y>Y-20 && y<Y+17)) /* Coordinate of button */
{
if(button&1==1) /* If left button is Pressed */
{
gotoxy(33,6); /* To Position Pressed number */
B=j*4+i; /* To get information about which button is Pressed */
setcolor(10);/* When the button is pressed the objects printed on button changes their color to green */
outtextxy(X,Y,text[j*4+i]);
/*********************************************/
switch(B)/>/>/>/>
{
case 0:
AddNum(1);
break;
case 1:
AddNum(2);
break;
case 2:
AddNum(3);
break;
case 3:
Operation(1);
break;
case 4:
AddNum(4);
break;
case 5:
AddNum(5);
break;
case 6:
AddNum(6);
break;
case 7:
Operation(2);
break;
case 8:
AddNum(7);
break;
case 9:
AddNum(8);
break;
case 10:
AddNum(9);
break;
case 11:
Operation(3);
break;
case 12:
Square();
break;
case 13:
AddNum(0);
break;
case 14:
Operation(5);
break;
case 15:
Operation(4);
break;
case 16:
num=0;
printf("                   ");
gotoxy(33,6);
printf("0");
break;
case 19:
HideMouse();
delay(1000);
cleardevice();
exit(0);
break;
}
/*********************************************/
delay(200);   /* Time Delay */
/* After button is pressed the color of printed objects on button is set to light red */
setcolor(12);
outtextxy(X,Y,text[j*4+i]);
}
}
X=X+60;
i++;
}while(i<4);
X=283;
Y=Y+60;
j++;
}while(j<5);
/******************************************/
}
}

/***************************************/
/* Calculator Draw */
/***************************************/
void CalculatorPics()
{
int x1,y1;
setcolor(12);
bar3d(250,50,500,370,8,8);
line(250,100,500,100);
setfillstyle(SOLID_FILL,RED);
floodfill(270,102,12);
floodfill(260,49,12);
floodfill(503,55,12);
setfillstyle(SOLID_FILL,BLACK);
floodfill(252,60,12);
setcolor(CYAN);
bar3d(260,110,310,140,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(270,120,CYAN);
bar3d(320,110,370,140,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(330,120,CYAN);
bar3d(380,110,430,140,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(390,120,CYAN);
bar3d(440,110,490,140,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(450,120,CYAN);
bar3d(260,170,310,200,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(270,180,CYAN);
bar3d(320,170,370,200,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(330,180,CYAN);
bar3d(380,170,430,200,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(390,180,CYAN);
bar3d(440,170,490,200,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(450,180,CYAN);
bar3d(260,230,310,260,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(270,240,CYAN);
bar3d(320,230,370,260,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(330,240,CYAN);
bar3d(380,230,430,260,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(390,240,CYAN);
bar3d(440,230,490,260,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(450,240,CYAN);
bar3d(260,290,310,320,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(270,300,CYAN);
bar3d(320,290,370,320,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(330,300,CYAN);
bar3d(380,290,430,320,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(390,300,CYAN);
bar3d(440,290,490,320,4,4);
setfillstyle(SOLID_FILL,BLUE);
floodfill(450,300,CYAN);
bar3d(260,340,310,370,4,4);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(270,350,CYAN);
bar3d(440,340,490,370,4,4);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(450,350,CYAN);
setcolor(GREEN);
outtextxy(330,340,"CALCULATOR");
setcolor(12);
x1=283;
y1=123;
j=0;
do
{
i=0;
do
{
outtextxy(x1,y1,text[j*4+i]);
x1=x1+60;
i++;
}while(i<4);
x1=283;
y1=y1+60;
j++;
}while(j<5);
}
/**********************/

int CallMouse()
{
in.x.ax=1;
int86(51,&in,&out);
return 1;
}
/************************/
int HideMouse()
{
in.x.ax=2;
int86(51,&in,&out);
return 1;
}
/**************************/
void MousePosi(int *Xpos,int *Ypos,int *Click)
{
in.x.ax=3;
int86(51,&in,&out);
*Click=out.x.bx;
*Xpos=out.x.cx;
*Ypos=out.x.dx;
}
/*****************************/

int AddNum(int pass)
{
num=num*10+pass;
printf("%ld",num);
return(0);
}

/************************************/

int Operation(int opr)
{
printf("              ");
gotoxy(33,6);
if(opr!=5)
{
pnum=num;
Opr=opr;
num=0;
}
else
{
anum=num;
num=0;
opr=0;
switch(Opr)
{
case 1:
total=pnum+anum;
break;
case 2:
total=pnum-anum;
break;
case 3:
total=pnum*anum;
break;
case 4:
total=pnum/anum;
break;
default :
total=anum;
break;
}
num=total;
printf("%ld",num);
}
return(0);
}

void Square()
{
num=num*num;
printf("%ld",num);
}



-animation ball
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <malloc.h>

void *buff;

void Draw_Ball()
{
	setcolor(RED);
	setfillstyle(SOLID_FILL,RED);
	circle(40,40,10);
	floodfill(40,40,RED);
	buff = malloc(imagesize(30,30,50,50));
	getimage(30,30,50,50,buff);
	putimage(30,30,buff,XOR_PUT);
}

void main()
{
	int gd=DETECT,gm;
	int XCoord = 0, YCoord = 0;
	int dx = 5, dy = 5;

	initgraph(&gd,&gm,"c://turboc3//bgi " /* path of bgi graphics */);

	setbkcolor(LIGHTGRAY);

	Draw_Ball();



	while(!kbhit())
	{
		putimage(XCoord,YCoord,buff,XOR_PUT);
		delay(40);
		putimage(XCoord,YCoord,buff,XOR_PUT);

		XCoord += dx;
		YCoord += dy;


		if(XCoord <=0)
		{
			XCoord = 0;
			dx = 5;
			sound(1000);
			delay(20);
		}
		else if(XCoord >= getmaxx() - 32)
		{
			XCoord = getmaxx() - 32;
			dx = -5;
			sound(1000);
			delay(20);
		}

		if(YCoord <=0)
		{
			YCoord = 0;
			dy = 5;
			sound(1000);
			delay(20);
		}
		else if(YCoord >= getmaxy() - 32)
		{
			YCoord = getmaxy()-32;
			dy = -5;
			sound(1000);
			delay(20);
		}


		nosound();


	}

	closegraph();

}


This post has been edited by Skydiver: 09 February 2019 - 08:10 AM
Reason for edit:: Fixed botched code tags. Thank you for trying!


Is This A Good Question/Topic? 0
  • +

Replies To: TO combine four different type of programs to make a single one

#2 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2295
  • View blog
  • Posts: 4,397
  • Joined: 30-May 10

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 03:33 AM

> i am working on a project in turbo c++.
Posted Image

Seriously dude, TC has been obsolete for 30 YEARS.

No one will pay for skills so obsolete.
Was This Post Helpful? 1
  • +
  • -

#3 Solemnghost   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-February 19

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 03:44 AM

Bro its not for payment purpose.
Its just an occasional topic that i am performing on a clz project.
If u know how to do so
please help me.
But if u dont know
Than i am sorry to bother u

This post has been edited by Skydiver: 09 February 2019 - 08:07 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2295
  • View blog
  • Posts: 4,397
  • Joined: 30-May 10

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 04:06 AM

> Bro its not for payment purpose.
Maybe not today, but are you looking to make a career as a programmer in the future?

> Its just an occasional topic that i am performing on a clz project.
What's a "clz"?
http://www.catb.org/....html#writewell

> If u know how to do so
Sure I know, but I'm not interested in perpetuating TurboCrap knowledge.

Pester your teacher as to why you're paying to be taught about obsolete technology.
Even if it's not cash out of your pocket, it's out of your parents' pockets (directly or indirectly).

Send your teacher here for some re-education.
Was This Post Helpful? 0
  • +
  • -

#5 Solemnghost   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-February 19

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 06:05 AM

Bro i thought if my teacher take the re-education .he is not gonaa be as good as u.
As it is clear from your
Reputation level.
Well i try any other way to solve my problem if you are not interested in answering

This post has been edited by Skydiver: 09 February 2019 - 08:05 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is online

  • member icon

Reputation: 5668
  • View blog
  • Posts: 17,402
  • Joined: 25-December 09

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 08:08 AM

Quote

Well i try any other way to solve my problem if you are not interested in answering

That's probably a good idea.

Some things to seriously consider going forward:

1. This is an English speaking board. Most of the people helping on this forum find "SMS Speak" both annoying and rude. So make sure you post in proper English.

2. And this is probably most important: Get and use a modern compiler, few if any of the people helping on this forum will help support such old decrepit tools. Especially tools that won't run on modern Operating Systems without some tweaking.

3. I suggest you download the current community edition of Visual Studio and start over using a modern graphic system like SDL, OpenGL, SFML, or Allegro.

4. Good Luck, especially if you stick with your current setup.

Jim
Was This Post Helpful? 1
  • +
  • -

#7 Solemnghost   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-February 19

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 08:44 AM

Thanks for your motivation sir.
I will remember your advices and work on it.

This post has been edited by Skydiver: 09 February 2019 - 09:08 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6717
  • View blog
  • Posts: 22,931
  • Joined: 05-May 12

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 09:06 AM

There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6717
  • View blog
  • Posts: 22,931
  • Joined: 05-May 12

Re: TO combine four different type of programs to make a single one

Posted 09 February 2019 - 07:34 PM

If you were good enough to write those four different programs, what is holding you back from combining them all into a single program? By any chance, did you "acquired" those 4 programs instead of writing them yourself? If you took the time to write them you would have built up your skill level up to the point where combining them is a trivial step.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1