Bouncing Ball Graphics Program in C++
#include<iostream> #include<graphics.h> #include<dos.h> using namespace std; void gotoxy(short x, short y) //definition of gotoxy function// { COORD pos ={x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void Delay(int dl){ for(int i= 0; i <= 10000; i++){ for(int j =0 ; j <= dl; j++){ } } } int dl, x = 300, y = 400, flag; void t1(){ if(y == 13 ){ flag = 2; } if(y == 450) flag = 8; } void Main(int f){ switch(f) { case 2: y+=1; dl = 60; break; case 8: y-=1; dl = 60; break; } Delay(dl); cleardevice(); t1(); circle(x,y,30); settextstyle(GOTHIC_FONT,HORIZ_DIR,1); outtextxy(350,450,"Press Esc key to exit."); } int main() { int gd = DETECT, gm ; initgraph(&gd,&gm,""); settextstyle(TRIPLEX_FONT,HORIZ_DIR,4); outtextxy(60,200,"Press any key to start."); getch(); flag = 8; while(1){ if(kbhit()){ //for Exit if(getch() == 27) break; } Main(flag); } getch(); return 0; }
Output :-
1 Comments