Ads

Wednesday, April 27, 2011

BRICK GAME IN C++

<br /> #include <iostream.h><br /> #include <conio.h><br /> #include <ctype.h> //defining toupper<br /> # include <process.h> //exit(0)<br /> # include <dos.h><br /> # include <stdlib.h><br /> # include <graphics.h><br /> # include <stdio.h><br /> <br /> # define NULL 0<br /> # define YES 1<br /> # define NO 0<br /> #define ESC 0x1b /* Define the escape key */<br /> <br /> int MaxX, MaxY, MidX, MidY ;<br /> int bri[5][20] ;<br /> <br /> int GraphDriver; /* The Graphics device driver */<br /> int GraphMode; /* The Graphics mode value */<br /> int MaxXX, MaxYY; /* The maximum resolution of the screen */<br /> int MaxColors; /* The maximum # of colors available */<br /> int ErrorCode; /* Reports any graphics errors */<br /> struct palettetype palette; /* Used to read palette info*/<br /> <br /> // Initialize the graphics mode<br /> void Initialize(void);<br /> <br /> // Display the last screen of bricks<br /> void SayGoodbye(void);<br /> <br /> // Changes the text style and report any error if encounter<br /> void changetextstyle(int font, int direction, int charsize);<br /> <br /> // Welcome screen of bricks game<br /> mainscreen();<br /> <br /> // Instruction messages of bricks game<br /> screen();<br /> <br /> // To display the bricks (in square box) and paddles in rectangle form <br /> and<br /> bulbs rounded form<br /> bricks();<br /> <br /> // Delete a bricks when bulb hit it<br /> delbrick(int,int);<br /> <br /> // Echoes different musics<br /> bell(int);<br /> <br /> int graphmode = CGAHI, graphdriver = CGA, level; // resolution of<br /> CGAHI = 640 x 200 (col x row)<br /> <br /> /*-------------------Mouse Library--------------*/<br /> <br /> void InitMouse()//initializes the mouse<br /> {<br /> union REGS in,out;<br /> in.x.ax=33;<br /> int86(0x33,&in,&out);<br /> }<br /> <br /> void MousePos(int* x,int* y,int* click)<br /> { //stores back (x,y) values and click type<br /> //click=1: left click<br /> //2: right click<br /> //3: middle click<br /> union REGS in,out;<br /> in.x.ax=3;<br /> int86(0x33,&in,&out);<br /> *click=(int)out.x.bx;<br /> *x=(int)out.x.cx;<br /> *y=(int)out.x.dx;<br /> }<br /> /*-----------------------End Of Mouse Methods----------*/<br /> <br /> <br /> main<br /> ()<br /> {<br /> union REGS ii, oo ;<br /> <br /> int BallX, BallY, Base1, Base2, dx = 1, dy = -1, OldX, OldY ;<br /> int totallayer[5] = { 10, 20, 30, 40, 50 }, max = 50, layer = 4 ;<br /> int i, flag = 0, speed = 15, score = 0, chance = 4, areareq ;<br /> <br /> char *m1, *m2 ; //pointers to memory<br /> <br /> /* Function to initialise the graphics mode */<br /> initgraph ( &graphdriver, &graphmode, "c:\tc\bgi" ) ;<br /> mainscreen();<br /> initgraph ( &graphdriver, &graphmode, "c:\tc\bgi" ) ;<br /> /**************************************************/<br /> /* Function to initialise the mouse */<br /> InitMouse();<br /> /* get the maximum value of x and y coordinates of the screen */<br /> MaxX = getmaxx() ;<br /> MaxY = getmaxy() ;<br /> /* finding the center of the screen */<br /> MidX = MaxX / 2 ;<br /> MidY = MaxY / 2 ;<br /> <br /> <br /> /* create opening screen and accept the level of the player's */<br /> level = screen() ;<br /> <br /> /* assign the speed to ball as per the level chosen */<br /> switch ( level )<br /> {<br /> case 'M' :<br /> case 'm' :<br /> speed = 10 ;<br /> break ;<br /> <br /> case 'F' :<br /> case 'f' :<br /> speed = 3 ;<br /> }<br /> <br /> /* draw the four layer of bricks, the paddle and the ball */<br /> rectangle ( 0, 0, MaxX, MaxY - 12 ) ;<br /> bricks() ;<br /> rectangle ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 12 ) ;<br /> floodfill ( MidX, MaxY - 1 - 12, 12 ) ;<br /> circle ( MidX, MaxY - 13 - 12, 12 ) ;<br /> <br /> // fillellipse ( MidX, MaxY - 13 - 12,12,12 ) ;<br /> floodfill ( MidX, MaxY - 10 - 12, 12 ) ;<br /> <br /> /* memory allocation for storing the image of the paddle */<br /> areareq = imagesize ( MidX - 12, MaxY - 18, MidX + 12, MaxY - 8 ) ;<br /> m1 =((char*) malloc ( areareq )) ;<br /> <br /> /* memory allocation for storing the image of the ball */<br /> areareq = imagesize ( MidX - 25, MaxY - 7, MidX + 25, MaxY - 1 ) ;<br /> m2 =((char *) malloc ( areareq ) );<br /> <br /> /* if unable to alloacte the memory */<br /> if ( m1 == NULL || m2 == NULL )<br /> {<br /> puts ( "Not Enough memory!!" ) ;<br /> exit ( 1 ) ;<br /> }<br /> <br /> /* image of the paddle and the ball is stored into allocated memory */<br /> getimage ( MidX - 12, MaxY - 7 - 12 - 12 + 1, MidX + 12, MaxY - 8 - <br /> 12,<br /> m1 ) ;<br /> getimage ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 1 - 12, m2 ) ;<br /> <br /> /* store current position of the paddle and ball */<br /> Base1 = MidX - 25 ;<br /> Base2 = MaxY - 7 - 12 ;<br /> BallX = MidX - 12 ;<br /> BallY = MaxY - 7 - 12 + 1 - 12 ;<br /> <br /> /* display balls remaining ( initially 3 ) */<br /> gotoxy ( 45, 25 ) ;<br /> cout<< "Balls :" ; for ( i = 0 ; i < 3 ; i++ ) { circle ( 515 + i * 35, MaxY - 5, 12 ) ; floodfill ( 515 + i * 35, MaxY - 5, 12 ) ; } /* display starting score */ gotoxy ( 1, 25 ) ; cout<< "Score: "; gotoxy(16,25); cout<<score; /* select font and alignment for displaying text */ settextjustify ( CENTER_TEXT, CENTER_TEXT ) ; changetextstyle ( GOTHIC_FONT, HORIZ_DIR, 4 ) ; while ( 1 ) { flag = 0 ; /* saving current x and y coordinates of the ball */ OldX = BallX ; OldY = BallY ; /* update ballx and bally to move the ball in correct direction */ BallX = BallX + dx ; BallY = BallY + dy ; /* according to the position of ball the layer of bricks is determined */ if ( BallY > 40 )<br /> {<br /> max = 50 ;<br /> layer = 4 ;<br /> }<br /> else<br /> {<br /> if ( BallY > 30 )<br /> {<br /> max = 40 ;<br /> layer = 3 ;<br /> }<br /> else<br /> {<br /> if ( BallY > 20 )<br /> {<br /> max = 30 ;<br /> layer = 2 ;<br /> }<br /> else<br /> {<br /> if ( BallY > 10 )<br /> {<br /> max = 20 ;<br /> layer = 1 ;<br /> }<br /> else<br /> {<br /> max = 10 ;<br /> layer = 0 ;<br /> }<br /> }<br /> }<br /> }<br /> <br /> /* if the ball hits the right boundary, move it to the left */<br /> if ( BallX > ( MaxX - 24 - 1 ) )<br /> {<br /> bell ( 5 ) ;<br /> BallX = MaxX - 24 - 1 ;<br /> dx = -dx ;<br /> }<br /> <br /> /* if the ball hits the left boundary, move it to the right */<br /> if ( BallX < 1 ) { bell ( 5 ) ; BallX = 1 ; dx = -dx ; } /* if the ball hits the top boundary, move it down */ if ( BallY < 1 ) { bell ( 5 ) ; BallY = 1 ; dy = -dy ; } /* if the ball is in the area of the bricks */ if ( BallY < max ) { /* if there is no brick at the top of the ball */ if ( bri[layer][ ( BallX + 10 ) / 32 ] == 1 ) { /* if the ball touches a brick */ for ( i = 1 ; i <= 6 ; i++ ) { /* check whether there is a brick to the right of the ball */ if ( bri[layer][ ( BallX + i + 10 ) / 32 ] == 0 ) { /* if there is a brick */ BallX = BallX + i ; flag = 1 ; break ; } /* check whether there is a brick to the left of the ball */ if ( bri[layer][ ( BallX - i + 10 ) / 32 ] == 0 ) { BallX = BallX - i ; flag = 1 ; break ; } } /* if the ball does not touch a brick at the top, left or right */ if ( !flag ) { /* check if the ball has moved above the current layer */ if ( BallY < totallayer[layer - 1] ) { /* if so, change current layer appropriately */ layer-- ; max = totallayer[layer] ; } /* restore the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, OR_PUT ) ; /* erase the image at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* place the image of the ball at the new coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* delay for fewseconds*/ delay ( speed ) ; /* carry on moving the ball */ continue ; } } /* when ball touch the brick control comes to this point */ bell ( 5 ) ; /* play music */ /* erase the touched brick */ delbrick ( ( BallX + 10 ) / 32, layer ) ; /* if the brick hit is on the extreme right */ if ( ( BallX + 10 ) / 32 == 19 ) line ( MaxX, 0, MaxX, 50 ) ; /* redraw right boundary */ /* if the brick hit is on the extreme left */ if ( ( BallX + 10 ) / 32 == 0 ) line ( 0, 0, 0, 50 ) ; /* redraw left boundary */ /* if the brick hit is in the topmost layer */ if ( layer == 0 ) line ( 0, 0, MaxX, 0 ) ; /* redraw top boundary */ /* set appropriate array element to 1 to indicate absence of brick */ bri[layer][ ( BallX + 10 ) / 32 ] = 1 ; BallY = BallY + 1 ; /* update the y coordinate */ dy = -dy ; /* change the current direction of the ball */ score += 10 ; /* increment the score by 10 */ gotoxy ( 16, 25 ) ; cout<< score; /* display latest score */ /* if the first brick is hit during a throw*/ } /* if ball reached the bottom */ if ( BallY > 180 - 12 )<br /> {<br /> <br /> <br /> /* if paddle missed the ball */<br /> if ( BallX < Base1 - 20 || BallX > Base1 + 50 )<br /> {<br /> /* continue the decrement of the ball */<br /> while ( BallY < 177 ) { /* erase the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* put the image of the ball at the new coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* introduce delay for fewseconds */ delay ( speed ) ; /* saveing current x and y coordinates of the ball */ OldX = BallX ; OldY = BallY ; /* update ballx and bally to move the ball in correct direction */ BallX = BallX + dx ; BallY = BallY + dy ; } chance-- ; /* decrement the total number of chances */ score -= 10 ; /* decrement 10 points for each ball lost */ gotoxy ( 16, 25 ) ; cout<< score; /* display latest score */ bell ( 1 ) ; /* erase one of the available balls */ if ( chance ) putimage ( 515 + ( chance - 1 ) * 35 - 12 , MaxY - 10, m1, XOR_PUT ) ; /* if the last ball is being played */ if ( chance == 1 ) { gotoxy ( 45, 25 ) ; cout<< "Last ball... careful!"; } /* if all the balls are lost */ if ( !chance ) { gotoxy ( 45, 25 ) ; cout<<"Press any key to continue ... " ; outtextxy ( MidX, MidY, "Better luck next time" ) ; bell ( 2 ) ; closegraph() ; restorecrtmode() ; closegraph(); /* Close the graphics mode */ Initialize(); /* Intialize the graphics mode */ setbkcolor(4); SayGoodbye(); /* Display the That's all Folks message */ closegraph(); /* Return the system to text mode */ exit ( 0 ) ; } } /* if ball is collected on paddle */ bell ( 4 ) ; BallY = 180 - 12 ; /* restore the y coordinate of ball */ dy = -dy ; /* move the ball upwards */ } /* put the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, OR_PUT ) ; /* erase the image of the ball at the old coordinates */ putimage ( OldX, OldY, m1, XOR_PUT ) ; /* put the image of the ball at the upadted coordinates */ putimage ( BallX, BallY, m1, XOR_PUT ) ; /* If score becomes 500 for every level player the speed of the ball will be standard PLAYER playing Fast level feel reduction of speed n PLAYER playing slow or medium level feel increment in speed... */ if(score==600) speed=6 ; /* if all the bricks have been knockout */ if ( score == 800 - ( ( 4 - chance ) * 10 ) ) { outtextxy ( MidX, MidY, "Winner !!" ) ; if ( score < 800 ) outtextxy ( MidX, MidY + 30, "Try to score 800" ) ; else outtextxy ( MidX, MidY + 30, " GREAT!" ) ; bell ( 2 ) ; SayGoodbye(); /* Display the That's all Folks message */ closegraph() ; restorecrtmode() ; exit ( 0 ) ; } /* introduce delay for few seconds */ delay ( speed ) ; /* if the key is pressed to exit the game */ if ( kbhit() ) { /* interrupt issue to obtain the ascii and scan codes of key hit */ ii.h.ah = 0 ; int86 ( 22, &ii, &oo ) ; /* if Esc key has been pressed */ if ( oo.h.ah == 1 ) exit ( 0 ) ; } /* put the image of the paddle at the old coordinates */ putimage ( Base1, Base2, m2, OR_PUT ) ; /* erase the image of the paddle at the old coordinates */ putimage ( Base1, Base2, m2, XOR_PUT ) ; // /* if Esc key has been pressed */ // if ( oo.h.ah == 1 ) // exit ( 0 ) ; /* right arrow key */ // if ( oo.h.ah == 75 ) // Base1 = //Base1 - 25 ; /* left arrow key */ // if ( oo.h.ah == 77 ) // Base1= Base1 + 25 ; /**********************************************************/ //dummy variables are useless //to get current x co-ordinate of the //mouse pointer pointer of Base1 is passed //the result is copied in the variable int ydummy,clickdummy; MousePos(&Base1,&ydummy,&clickdummy); /* if paddle goes beyond left boundary */ if ( Base1 < 0 ) Base1 = 0 ; /* if paddle goes beyond right boundary */ if ( Base1 > 589 )<br /> Base1 = 589 ;<br /> /* put the image of the paddle at the proper position */<br /> putimage ( Base1, Base2, m2, XOR_PUT ) ;<br /> // }<br /> }<br /> closegraph();<br /> Initialize();<br /> SayGoodbye(); /* Give user the closing screen */<br /> closegraph(); /* Return the system to text mode */<br /> return(0);<br /> }<br /> <br /> /* This function creates the opening screen and displyed instruction<br /> related to the game<br /> along with two option play or exit.After selecting the paly option it<br /> display<br /> three levels of the game and according to your choice you can select <br /> any<br /> level.<br /> This selected level is returned by this function to the mainprogram<br /> according to which<br /> the speed is assigned to the ball*/<br /> <br /> screen()<br /> {<br /> int i, j, lx = 0, ly = 0, ch ;<br /> <br /> <br /> rectangle(1,1,600,195);<br /> setbkcolor(4);<br /> /* set the textstyle for displaying instruction */<br /> changetextstyle ( DEFAULT_FONT, HORIZ_DIR, 0 ) ;<br /> outtextxy ( 150, 55, " Instructions " ) ;<br /> changetextstyle (4, HORIZ_DIR, 5 );<br /> outtextxy ( 130, 0, " B R I C K S" ) ;<br /> changetextstyle ( DEFAULT_FONT, HORIZ_DIR, 0 ) ;<br /> outtextxy ( 30, 68, "Use mouse to move the paddle" ) ; // can also <br /> use<br /> KEYBOARD after activating keyboard event (use LEFT and RIGHT keys to <br /> move<br /> the PADDLE<br /> outtextxy ( 30, 88, "If you don't collect the ball on the paddle, you<br /> lose the ball." ) ;<br /> outtextxy ( 30, 108, "On loosing a ball you loose 10 points." ) ;<br /> outtextxy ( 30, 128, "On taking a brick you gain 10 points." ) ;<br /> changetextstyle(7, HORIZ_DIR, 3);<br /> outtextxy ( 100, 148, "Press any key to continue ..." ) ;<br /> bell ( 3 ) ; /* ring music */<br /> fflush ( stdin ) ;<br /> // if ( getch() == 0 )<br /> // getch() ;<br /> <br /> closegraph();<br /> initgraph ( &graphdriver, &graphmode, "c:\tc\bgi" ) ;<br /> rectangle(2,2,620,195);<br /> setbkcolor(4);<br /> /* display the main menu */<br /> while ( 1 )<br /> {<br /> <br /> changetextstyle(4,HORIZ_DIR,5);<br /> outtextxy ( 60, 8, "Options Available:" ) ;<br /> outtextxy ( 150, 55, "Play ( P )" ) ;<br /> outtextxy ( 150, 125, "Exit ( E )" ) ;<br /> <br /> ch = 0 ;<br /> <br /> /* continue untill you select the correct choice */<br /> while ( ! ( ch == 'E' || ch == 'P' ) )<br /> {<br /> fflush ( stdin ) ;<br /> <br /> /* if a special key is hit, flush the keyboard buffer */<br /> if ( ( ch = getch() ) == 0 )<br /> getch() ;<br /> else<br /> ch = toupper ( ch ) ; /* store the uppercase of the choice <br /> made*/<br /> }<br /> <br /> if ( ch == 'P' )<br /> break ;<br /> if (ch == 'E')<br /> exit ( 0 ) ;<br /> <br /> }<br /> <br /> // setviewport ( 1, 125 - 12, MaxX - 1, MaxY - 1, 1 ) ;<br /> // clearviewport() ;<br /> closegraph();<br /> initgraph ( &graphdriver, &graphmode, "c:\tc\bgi" ) ;<br /> rectangle(2,2,620,195);<br /> setbkcolor(4);<br /> <br /> /* display menu for the diffrent levels */<br /> changetextstyle(7,HORIZ_DIR,3);<br /> outtextxy ( 60, 8, "Select the level for play:" ) ;<br /> outtextxy ( 150,50, "Slow ( S )" ) ;<br /> outtextxy ( 150, 100, "Medium ( M )" ) ;<br /> outtextxy ( 150, 150, "Fast ( F )" ) ;<br /> <br /> /* accept user's choice */<br /> fflush ( stdin ) ;<br /> if ( ( ch = getch() ) == 0 )<br /> getch() ;<br /> <br /> clearviewport() ;<br /> <br /> /* return the choice selected by the user */<br /> return ( ch ) ;<br /> }<br /> <br /> /* This function draws bricks at the start of the game.There are four<br /> layers of<br /> the bricks */<br /> bricks()<br /> {<br /> int i, j, lx = 0, ly = 0 ;<br /> <br /> for ( i = 0 ; i < 5 ; i++ ) /* 5 rows */ { for ( j = 0 ; j < 30 ; j++ ) /* 20 columns */ { /* draw a brick at appropriate coordinates */ rectangle ( lx, ly, lx + 20, ly + 7 ) ; floodfill ( lx + 1, ly + 1, 2 ) ; lx = lx + 32 ; } lx = 0 ; ly = ly + 10 ; } } /* This function erases the brick which is knock by the ball */ delbrick ( int b, int l ) { /* b - brick number, l - layer */ setcolor ( BLACK ) ; rectangle ( b * 32, l * 10, ( b * 32 ) + 20 , ( l * 10 ) + 7 ) ; rectangle ( b * 32 + 1, l * 10, ( b * 32 ) + 20 - 1, ( l * 10 ) + 7 - 1 ) ; rectangle ( b * 32 + 2, l * 10, ( b * 32 ) + 20 - 2, ( l * 10 ) + 7 - 2 ) ; rectangle ( b * 32 + 3, l * 10, ( b * 32 ) + 20 - 3, ( l * 10 ) + 7 - 3 ) ; rectangle ( b * 32 + 4, l * 10, ( b * 32 ) + 20 - 4, ( l * 10 ) + 7 - 4 ) ; rectangle ( b * 32 + 5, l * 10, ( b * 32 ) + 20 - 5, ( l * 10 ) + 7 - 5 ) ; rectangle ( b * 32 + 6, l * 10, ( b * 32 ) + 20 - 6, ( l * 10 ) + 7 - 6 ) ; setcolor ( CGA_YELLOW ) ; } /* plays different types of music */ bell ( int m_no ) { /* natural frequencies of 7 notes */ float wave[6] = { 120.81, 136.83, 144.81, 154.61, 216, 240 } ; int n, i ; switch ( m_no ) { case 1 : for ( i = 0 ; i < 6 ; i++ ) { sound ( wave[i] * 1 ) ; delay ( 30 ) ; } nosound() ; break ; case 2 : for ( i = 0 ; i < 15 ; i++ ) { n = random ( 6 ) ; sound ( wave[n] * 2 ) ; delay ( 100 ) ; } nosound() ; break ; case 3 : // while ( !kbhit() ) { n = random ( 6 ) ; sound ( wave[n] * 2 ) ; delay ( 100 ) ; } nosound() ; /* flush the keyboard buffer */ if ( getch() == 0 ) getch() ; break ; case 4 : for ( i = 5 ; i >= 0 ; i-- )<br /> {<br /> sound ( wave[i] * 4 ) ;<br /> delay ( 15 ) ;<br /> }<br /> nosound() ;<br /> break ;<br /> <br /> case 5 :<br /> sound ( wave[2] * 5 ) ;<br /> delay ( 50 ) ;<br /> nosound() ;<br /> }<br /> }<br /> /* */<br /> /* INITIALIZE: Initializes the graphics system and reports */<br /> /* any errors which occured. */<br /> /* */<br /> <br /> void Initialize(void)<br /> {<br /> int xasp, yasp; /* Used to read the aspect ratio*/<br /> <br /> GraphDriver = DETECT; /* Request auto-detection */<br /> initgraph( &GraphDriver, &GraphMode, "c:\tc\bgi" );<br /> ErrorCode = graphresult(); /* Read result of initialization*/<br /> if( ErrorCode != grOk ){ /* Error occured during init */<br /> printf(" Graphics System Error: %s<br /> ", grapherrormsg( ErrorCode ) );<br /> exit( 1 );<br /> }<br /> <br /> getpalette( &palette ); /* Read the palette from board */<br /> MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/<br /> <br /> MaxXX = getmaxx();<br /> MaxYY = getmaxy(); /* Read size of screen */<br /> <br /> <br /> }<br /> /* */<br /> /* SAYGOODBYE: Give a closing screen to the user before leaving. */<br /> /* */<br /> <br /> void SayGoodbye(void)<br /> {<br /> struct viewporttype viewinfo; /* Structure to read viewport */<br /> int h, w;<br /> <br /> // MainWindow( "== Finale ==" );<br /> <br /> getviewsettings( &viewinfo ); /* Read viewport settings */<br /> changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );<br /> settextjustify( CENTER_TEXT, CENTER_TEXT );<br /> <br /> h = viewinfo.bottom - viewinfo.top;<br /> w = viewinfo.right - viewinfo.left;<br /> cleardevice();<br /> <br /> // StatusLine( "Press any key to EXIT" );<br /> <br /> getch();<br /> <br /> cleardevice(); /* Clear the graphics screen */<br /> <br /> }<br /> <br /> <br /> <br /> //}<br /> <br /> /* */<br /> /* CHANGETEXTSTYLE: similar to settextstyle, but checks for */<br /> /* errors that might occur while loading the font file. */<br /> /* */<br /> <br /> void changetextstyle(int font, int direction, int charsize)<br /> {<br /> int ErrorCode;<br /> <br /> graphresult(); /* clear error code */<br /> settextstyle(font, direction, charsize);<br /> ErrorCode = graphresult(); /* check result */<br /> if( ErrorCode != grOk ){ /* if error occured */<br /> closegraph();<br /> printf(" Graphics System Error: %s<br /> ", grapherrormsg( ErrorCode ) );<br /> exit( 1 );<br /> }<br /> }<br /> <br /> /* The main function body of main screen which displays the main screen<br /> creating the opening screen display */<br /> mainscreen()<br /> {<br /> int maxx, maxy, in, area;<br /> <br /> // get maximum x, y coordinates of the screen<br /> maxx = getmaxx();<br /> maxy = getmaxy();<br /> <br /> // setbkcolor sets the current background color using the palette<br /> setbkcolor(RED);<br /> <br /> // Draws a rectangle (graphics mode)<br /> rectangle(0, 0, maxx, maxy);<br /> <br /> // sets the line style and text justification in screen<br /> changetextstyle(10, HORIZ_DIR, 4);<br /> <br /> // displaying the output text on main screen<br /> outtextxy(140, 0, " WELCOME");<br /> outtextxy(170,50," TO ");<br /> outtextxy(140,100," BRICKS");<br /> changetextstyle(7, HORIZ_DIR, 3);<br /> bell(3);<br /> outtextxy(110, 160, "Press any key to continue...");<br /> <br /> // Flushes the standard input device<br /> fflush(stdin);<br /> getch();<br /> closegraph();<br /> <br /> }<br /> <br />

SNAKE GAME IN C++

<br /> #include<stdlib.h><br /> #include<stdio.h><br /> #include<conio.h><br /> <br /> /* prototypes */<br /> <br /> void draw_line(int col, int row);<br /> <br /> void show_score();<br /> <br /> void add_segment();<br /> <br /> void setup_level();<br /> <br /> <br /> <br /> /* constants */<br /> <br /> const int maxrow=15, maxcol=77;<br /> <br /> const int snake_start_col=33,snake_start_row=7;<br /> <br /> const char up_key='a', down_key='z', left_key='o', right_key='p';<br /> <br /> const int pause_length=500000;<br /> <br /> <br /> <br /> /* global variables */<br /> <br /> int score, snake_length, speed, obstacles, level, firstpress, high_score=0;<br /> <br /> char screen_grid[maxrow][maxcol];<br /> <br /> char direction = right_key;<br /> <br /> struct snake_segment {<br /> <br /> int row,col;<br /> <br /> } snake[100];<br /> <br /> <br /> void main()<br /> <br /> {<br /> <br /> <br /> <br /> /* Variable declarations within main() only */<br /> <br /> char keypress;<br /> <br /> <br /> <br /> do /* restart game loop */<br /> <br /> {<br /> <br /> obstacles=4; level=1; score=0; speed=14;<br /> <br /> <br /> <br /> randomize(); /* Ensure random seed initiated */<br /> <br /> <br /> <br /> setup_level();<br /> <br /> <br /> <br /> /* main loop */<br /> <br /> do<br /> <br /> {<br /> <br /> for (int i=0;i<(speed*pause_length);i++) int j=1+i; /*pause*/ /* If key has been hit, then check it is a direction key - if so, change direction */ if (kbhit()) { keypress=(char)getch(); if((keypress==right_key)||(keypress==left_key)|| (keypress==up_key)||(keypress==down_key)) direction = keypress; } /* Add a segment to the end of the snake */ add_segment(); /* Blank last segment of snake */ gotoxy(snake[0].col,snake[0].row); cprintf(" "); /* ... and remove it from the array */ for (int i=1;i<=snake_length;i++) snake[i-1]=snake[i]; /* Display snake in yellow */ textcolor(YELLOW); for (int i=0;i<=snake_length;i++) { gotoxy(snake[i].col,snake[i].row); cprintf("O"); } /* keeps cursor flashing in one place instead of following snake */ gotoxy(1,1); /* If first press on each level, pause until a key is pressed */ if (firstpress) { while(!kbhit()); firstpress = 0; } /* Collision detection - walls (bad!) */ if ((snake[snake_length-1].row>maxrow+1)||(snake[snake_length-1].row<=1)|| (snake[snake_length-1].col>maxcol+1)||(snake[snake_length-1].col<=1)|| /* Collision detection - obstacles (bad!) */ (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='x')) keypress='x'; /* i.e. exit loop - game over */ /* Collision detection - snake (bad!) */ for (int i=0;i<snake_length-1;i++) if ( (snake[snake_length-1].row)==(snake[i].row) && (snake[snake_length-1].col)==(snake[i].col)) { keypress='x'; /* i.e. exit loop - game over */ break; /* no need to check any more segments */ } /* Collision detection - food (good!) */ if (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='.') { /* increase score and length of snake */ score+=snake_length*obstacles; show_score(); snake_length++; add_segment(); /* if length of snake reaches certain size, onto next level */ if (snake_length==(level+3)*2) { score+=level*1000; obstacles+=2; level++; /* add to obstacles */ if ((level%5==0)&&(speed>1)) speed--; /* increase speed every 5 levels */<br /> <br /> setup_level(); /* display next level */<br /> <br /> }<br /> <br /> }<br /> <br /> } while (keypress!='x');<br /> <br /> <br /> <br /> /* game over message */<br /> <br /> if (score > high_score) high_score = score;<br /> <br /> show_score();<br /> <br /> gotoxy(30,6); textcolor(LIGHTRED); cprintf("G A M E O V E R");<br /> <br /> gotoxy(30,9); textcolor(YELLOW); cprintf("Another Game (y/n)? ");<br /> <br /> do keypress=getch(); while((keypress!='y')&&(keypress!='n'));<br /> <br /> <br /> <br /> } while (keypress=='y');<br /> <br /> }<br /> <br /> <br /> <br /> void setup_level()<br /> <br /> {<br /> <br /> <br /> <br /> /* variables local to setup_level() */<br /> <br /> int row,col;<br /> <br /> <br /> <br /> /* Set up global variables for new level */<br /> <br /> snake_length=level+4; direction = right_key;<br /> <br /> firstpress = 1;<br /> <br /> /* Fill grid with blanks */<br /> <br /> for(row=0;row<maxrow;row++) for(col=0;col<maxcol;col++) screen_grid[row][col]= ' '; /* Fill grid with Xs and food */ for(int i=0;i<obstacles*2;i++) { row= rand()%maxrow; col= rand()%maxcol; if(i<obstacles) screen_grid[row][col]='x'; else screen_grid[row][col]='.'; } /* Create snake array of length snake_length */ for(int i=0;i<snake_length;i++) { snake[i].row=snake_start_row; snake[i].col=snake_start_col+i; } /* Draw playing board */ draw_line(1,1); for(row=0;row<maxrow;row++) { gotoxy(1,row+2); textcolor(LIGHTBLUE); cprintf("|"); textcolor(WHITE); for(col=0;col<maxcol;col++) cprintf("%c",screen_grid[row][col]); textcolor(LIGHTBLUE); cprintf("|"); } draw_line(1,maxrow+2); show_score(); gotoxy(2,maxrow+5); textcolor(LIGHTRED); cprintf("~~ SNAKE GAME~~ Left: %c, Right: %c, Up: %c, Down: %c, Exit: x. Any key to start.", left_key,right_key,up_key,down_key); } void draw_line(int col, int row) { gotoxy(col,row); textcolor(LIGHTBLUE); for (int col=0;col<maxcol+2;col++) cprintf("="); } void show_score() { textcolor(LIGHTCYAN); gotoxy(2,maxrow+3); cprintf("Level: %05d",level); gotoxy(40,maxrow+3); textcolor(LIGHTGREEN); cprintf("Score: %05d",score); gotoxy(60,maxrow+3); textcolor(LIGHTMAGENTA); cprintf("High Score: %05d",high_score); } void add_segment() { switch(direction) { case(right_key): snake[snake_length].row=snake[snake_length-1].row; snake[snake_length].col=snake[snake_length-1].col+1; break; case(left_key) : snake[snake_length].row=snake[snake_length-1].row; snake[snake_length].col=snake[snake_length-1].col-1; break; case(up_key) : snake[snake_length].row=snake[snake_length-1].row-1; snake[snake_length].col=snake[snake_length-1].col; break; case(down_key) : snake[snake_length].row=snake[snake_length-1].row+1; snake[snake_length].col=snake[snake_length-1].col; } }

A car racing game using c++

/*
Language: C\C++ (To convert to C, just change cout
to printf and cin to scanf and change the library files)
Category: Games\Graphics
Description: RACE CRAZE::A car racing game.

You have to reach the finish line before the time goes out.
There are many hurdles in your way.
So be careful.
*/

#include
#include
#include
#include
#include
#include
#include
#include


class car
{
private:
int x1,y1,x2,y2,col,col2,col3;
public:
car():x1(200),y1(300),x2(270),y2(200),col(4)
{}
car(int a,int b,int c,int d,int e,int f,int
g):x1(a),y1(b),x2(c),y2(d),col(e),col2(f),col3(g)
{}
void get(int a,int b,int c,int d,int e,int f,int g)
{
x1=a;
y1=b;
x2=c;
y2=d;
col=e;
col2=f;
col3=g;
if (x1<=180) { sound(1000); x1=200; x2=270; } if (x2>=430)
{
sound(1000);
x1=340;
x2=410;
}
}
void draw()
{
setcolor(col);
setfillstyle(1,col);
rectangle(x1,y1,x2,y2); //car body
floodfill(x1+10,y2+10,col);
setcolor(col2); //windows
setfillstyle(2,col2);
rectangle(x1+10,y1-70,x2-10,y2+10);
floodfill(x1+15,y2+15,col2);
rectangle(x1+10,y1-10,x2-10,y2+70);
floodfill(x1+15,y1-15,col2);
setcolor(col3); //wheels
setfillstyle(1,col3);
rectangle(x1-10,y2+5,x1,y2+20);
floodfill(x1-4,y2+12,col3);
rectangle(x2,y2+5,x2+10,y2+20);
floodfill(x2+4,y2+12,col3);
rectangle(x1-15+1,y1-25,x1,y1-5);
floodfill(x1-10,y1-20,col3);
rectangle(x2,y1-25,x2+15,y1-5);
floodfill(x2+4,y1-20,col3);
}
void collide(int col)
{
setcolor(col);
setfillstyle(1,col);
line(x1-5,y2-3,x1,y2);
line(x1-5,y2-5,x1,y2-5);
line(x1-5,y2-3,x1-5,y2-5);
line(x1,y2-5,x1+5,y2-3);
line(x1+5,y2-3,x1+10,y2-15);
line(x1+10,y2-15,x1+20,y2-3);
line(x1+20,y2-3,x1+30,y2-10);
line(x1+30,y2-10,x1+35,y2-3);
line(x1+35,y2-3,x1+45,y2-12);
line(x1+45,y2-12,x1+55,y2-3);
line(x1+55,y2-3,x1+60,y2-10);
line(x1+60,y2-10,x1+70,y2-3);
line(x1+70,y2-3,x1+74,y2-8);
line(x1+74,y2-8,x1+70,y2);
line(x1,y2,x1+70,y2);
floodfill(x1+30,y2-1,col);
line(x1-5,y1+3,x1,y1);
line(x1-5,y1+5,x1,y1+5);
line(x1-5,y1+3,x1-5,y1+5);
line(x1,y1+5,x1+5,y1+3);
line(x1+5,y1+3,x1+10,y1+15);
line(x1+10,y1+15,x1+20,y1+3);
line(x1+20,y1+3,x1+30,y1+10);
line(x1+30,y1+10,x1+35,y1+3);
line(x1+35,y1+3,x1+45,y1+12);
line(x1+45,y1+12,x1+55,y1+3);
line(x1+55,y1+3,x1+60,y1+10);
line(x1+60,y1+10,x1+70,y1+3);
line(x1+70,y1+3,x1+74,y1+8);
line(x1+74,y1+8,x1+70,y1);
line(x1,y1,x1+70,y1);
floodfill(x1+30,y1+1,col);
}
};


class obstacle
{
private:
int x,y,col;
public:
obstacle():x(0),y(0),col(0)
{}
obstacle(int a,int b,int c):x(a),y(b),col(c)
{}
void get(int a,int b,int c)
{
x=a;
y=b;
col=c;
}
void draw()
{
setcolor(col);
setfillstyle(1,col);
circle(x,y,20);
floodfill(x,y,col);
}
};


class timer
{
private:
int sec,min,ms,flag;
public:
timer():min(0),sec(0),ms(0),flag(0)
{}
timer(int a,int b,int c,int d):min(a),sec(b),ms(c),flag(d)
{}
void start()
{
min=sec=ms=flag=0;
}
void get()
{
settextstyle(1,0,1);
char* minn;
if (min>9)
{
int minnn=min/10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(20,100,minn);
setcolor(0);
outtextxy(20,100,minn);
}
if (min>9)
{
int minnn=min%10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(30,100,minn);
setcolor(0);
outtextxy(30,100,minn);
}
if (min<=9) { int minnn=min; if (minnn==0) minn="0"; if (minnn==1) minn="1"; if (minnn==2) minn="2"; if (minnn==3) minn="3"; if (minnn==4) minn="4"; if (minnn==5) minn="5"; if (minnn==6) minn="6"; if (minnn==7) minn="7"; if (minnn==8) minn="8"; if (minnn==9) minn="9"; setcolor(15); outtextxy(20,100,minn); setcolor(0); outtextxy(20,100,minn); } setcolor(15); outtextxy(40,100,":"); if (sec>9)
{
int minnn=sec/10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(50,100,minn);
setcolor(0);
outtextxy(50,100,minn);
}
if (sec>9)
{
int minnn=sec%10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(60,100,minn);
setcolor(0);
outtextxy(60,100,minn);
}
if (sec<=9) { int minnn=sec; if (minnn==0) minn="0"; if (minnn==1) minn="1"; if (minnn==2) minn="2"; if (minnn==3) minn="3"; if (minnn==4) minn="4"; if (minnn==5) minn="5"; if (minnn==6) minn="6"; if (minnn==7) minn="7"; if (minnn==8) minn="8"; if (minnn==9) minn="9"; setcolor(15); outtextxy(50,100,minn); setcolor(0); outtextxy(50,100,minn); } setcolor(15); outtextxy(70,100,":"); if (ms>9)
{
int minnn=ms/10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(80,100,minn);
setcolor(0);
outtextxy(80,100,minn);
}
if (ms>9)
{
int minnn=ms%10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(90,100,minn);
setcolor(0);
outtextxy(90,100,minn);
}
if (ms<=9) { int minnn=ms; if (minnn==0) minn="0"; if (minnn==1) minn="1"; if (minnn==2) minn="2"; if (minnn==3) minn="3"; if (minnn==4) minn="4"; if (minnn==5) minn="5"; if (minnn==6) minn="6"; if (minnn==7) minn="7"; if (minnn==8) minn="8"; if (minnn==9) minn="9"; setcolor(15); outtextxy(80,100,minn); setcolor(0); outtextxy(80,100,minn); } } void time() { ms++; if (ms==100) { ms=0; sec++; } if (sec==60) { sec=0; min++; } } int minutes() { return min; } void timego() { ms=0; sec+=30; if (sec>60)
{
sec=0;
min++;
}
}
};
void grass()
{
setcolor(10);
setfillstyle(1,10);
rectangle(0,0,180,400);
floodfill(10,100,10);
rectangle(430,0,600,400);
floodfill(480,100,10);
setcolor(5);
settextstyle(8,0,3);
outtextxy(440,50,"RACE CRAZE");
setcolor(0);
setfillstyle(1,0);
settextstyle(7,0,2);
outtextxy(20,60,"TIMER");
rectangle(20,100,150,130);
floodfill(60,120,0);
settextstyle(7,0,2);
outtextxy(20,260,"MILES");
rectangle(20,300,150,330);
floodfill(60,320,0);
}
void track(int n,int coll)
{
setcolor(coll);
setfillstyle(1,coll);
rectangle(300,n,310,50+n);
floodfill(302,10+n,coll);
rectangle(300,100+n,310,150+n);
floodfill(302,110+n,coll);
rectangle(300,200+n,310,250+n);
floodfill(302,210+n,coll);
rectangle(300,300+n,310,350+n);
floodfill(302,310+n,coll);
rectangle(300,400+n,310,450+n);
floodfill(302,410+n,coll);
rectangle(300,500+n,310,550+n);
floodfill(302,510+n,coll);
rectangle(300,600+n,310,650+n);
floodfill(302,610+n,coll);
rectangle(300,700+n,310,750+n);
floodfill(302,710+n,coll);
}
void main()
{
int driver,mode;
driver=EGA;
mode=EGAHI;
initgraph(&driver,&mode,"c:\\tc\\bgi");
car c,c1;
obstacle o;
timer T;
int i,j=200,k=200;
int t=-200,flg=0;
time_t tt,ttt;
c.get(k,j+100,k+70,j,4,3,8);
c.draw();
grass();
track(t,15);
randomize();
int r=0,r1,l=50;
int miles=0,mil=0;
int stage=10;
getch();
do
{
T.get();
i=0;
if (kbhit())
i=getch();
T.time();
char* minn;
settextstyle(1,0,1);
if (miles>99)
{
int minnn=miles/100;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(30,310,minn);
setcolor(0);
outtextxy(30,310,minn);
}
if (miles>99)
{
int minnn=miles%100;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(40,310,minn);
setcolor(0);
outtextxy(40,310,minn);
}
if (miles>9)
{
int minnn=miles/10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(40,310,minn);
setcolor(0);
outtextxy(40,310,minn);
}
if (miles>9)
{
int minnn=miles%10;
if (minnn==0)
minn="0";
if (minnn==1)
minn="1";
if (minnn==2)
minn="2";
if (minnn==3)
minn="3";
if (minnn==4)
minn="4";
if (minnn==5)
minn="5";
if (minnn==6)
minn="6";
if (minnn==7)
minn="7";
if (minnn==8)
minn="8";
if (minnn==9)
minn="9";
setcolor(15);
outtextxy(50,310,minn);
setcolor(0);
outtextxy(50,310,minn);
}
if (miles<=9) { int minnn=miles; if (minnn==0) minn="0"; if (minnn==1) minn="1"; if (minnn==2) minn="2"; if (minnn==3) minn="3"; if (minnn==4) minn="4"; if (minnn==5) minn="5"; if (minnn==6) minn="6"; if (minnn==7) minn="7"; if (minnn==8) minn="8"; if (minnn==9) minn="9"; setcolor(15); outtextxy(40,310,minn); setcolor(0); outtextxy(40,310,minn); } if (flg==0) { randomize(); srand((unsigned) time(&ttt)); r=rand()%3; if (r==2) { randomize(); r1=random(10)%2; l=100; (r1==0)?c1.get(200,l+stage,270,l+stage-100,5,6,7): c1.get(335,l+stage,405,l+stage-100,5,6,7); c1.draw(); flg=2; } } sound(miles+100); if (i==75) { c.get(k,j+100,k+70,j,0,0,0); c.draw(); k=200; c.get(k,j+100,k+70,j,4,3,8); if (flg==1) { c1.collide(14); c.collide(14); delay(500); c1.collide(0); c.collide(0); flg=3; T.timego(); } c.draw(); } if (i==155) { c.get(k,j+100,k+70,j,0,0,0); c.draw(); k=200; c.get(k,j+100,k+70,j,4,3,8); if (flg==1) { c1.collide(14); c.collide(14); delay(500); c1.collide(0); c.collide(0); flg=3; T.timego(); } c.draw(); } if (i==77) { c.get(k,j+100,k+70,j,0,0,0); c.draw(); k=335; c.get(k,j+100,k+70,j,4,3,8); if (flg==1) { c1.collide(14); c.collide(14); delay(500); c1.collide(0); c.collide(0); flg=3; T.timego(); } c.draw(); } if (i==157) { c.get(k,j+100,k+70,j,0,0,0); c.draw(); k=335; c.get(k,j+100,k+70,j,4,3,8); if (flg==1) { c1.collide(14); c.collide(14); delay(500); c1.collide(0); c.collide(0); T.timego(); flg=3; } c.draw(); } if (i==72) { mil+=1; track(t,0); (t>70)?t=-200:t+=5;
track(t,15);
if ((l+stage)>=200 && (l+stage)<=300) { if (r1==0 && k==200) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0): c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else if (r1==1 && k==335) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0): c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else flg=2; } if (flg==1) { c.collide(14); c1.collide(14); flg=0; delay(1000); c.collide(0); c1.collide(0); c.get(k,j+100,k+70,j,4,3,8); c.draw(); T.timego(); } if (flg==2) { (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0): c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); l=l+5; (r1==0)?c1.get(200,l+stage,270,l+stage-100,5,6,7) :c1.get(335,l+stage,405,l+stage-100,5,6,7); c1.draw(); if (l+stage>300)
flg=3;
}
}
if (i==152)
{
mil+=2;
track(t,0);
(t>70)?t=-200:t+=20;
track(t,15);
if (l+stage>=200 && l+stage<=300) { if (r1==0 && k==200) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0): c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else if (r1==1 && k==335) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0): c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else flg=2; } if (flg==1) { c.collide(14); c1.collide(14); flg=0; delay(1000); c.collide(0); c1.collide(0); c.get(k,j+100,k+70,j,4,3,8); c.draw(); T.timego(); } if (flg==2) { (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); l+=10; (r1==0)?c1.get(200,l+stage,270,l+stage-100,5,6,7) :c1.get(335,l+stage,405,l+stage-100,5,6,7); c1.draw(); if (l+stage>300)
flg=3;
}
}
if (i==80)
{
mil-=1;
track(t,0);
(t<-370)?t=-200:t-=5; track(t,15); if (l+stage>=200 && l+stage<=300) { if (r1==0 && k==200) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else if (r1==1 && k==335) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else flg=2; } if (flg==1) { c.collide(14); c1.collide(14); flg=0; delay(1000); c.collide(0); c1.collide(0); c.draw(); T.timego(); } if (flg==2) { (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); l=l-5; (r1==0)?c1.get(200,l+stage,270,l+stage-100,5,6,7) :c1.get(335,l+stage,405,l+stage-100,5,6,7); c1.draw(); if (l+stage>300)
flg=3;
}
}
if (i==160)
{
mil-=2;
track(t,0);
(t<-370)?t=-200:t-=20; track(t,15); if (l+stage>=200 && l+stage<=300) { if (r1==0 && k==200) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else if (r1==1 && k==335) { flg=1; (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); } else flg=2; } if (flg==1) { c.collide(14); c1.collide(14); flg=0; delay(1000); c.collide(0); c1.collide(0); c.draw(); T.timego(); } if (flg==2) { (r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0) :c1.get(335,l+stage,405,l+stage-100,0,0,0); c1.draw(); l=l-10; (r1==0)?c1.get(200,l+stage,270,l+stage-100,5,6,7) :c1.get(335,l+stage,405,l+stage-100,5,6,7); c1.draw(); if (l+stage>300)
flg=3;
}
}
if (flg==3)
{

(r1==0)?c1.get(200,l+stage,270,l+stage-100,0,0,0)
:c1.get(335,l+stage,405,l+stage-100,0,0,0);

c1.draw();
flg=0;
}
if (i==32)
{
sound(2000);
delay(200);
}
nosound();
if (mil>4)
{
miles+=1;
mil=0;
}
if (mil<-4) { miles-=1; mil=0; } if (miles>=1000)
break;
}while(i!='\r');
if (miles>=1000)
{
sound(3000);
clearviewport();
settextstyle(8,0,1);
int i=T.minutes();
if (i<8) outtextxy(50,100,"CONGRATULATIONS! \ You have won the competetion"); else outtextxy(50,100,"SORRY! You fell \ out of time"); delay(1000); getch(); nosound(); } }