Brick

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Brick as PDF for free.

More details

  • Words: 483
  • Pages: 6
/* // this is a brick ball game */ #include #include #include <stdlib.h> #include <stdio.h> #include #include <dos.h> int cx,cy,xp,yp,initial,flag=0,score; int incx,incy,game,count,width; int left,right,bottom,top; int b_left,b_top,b_right,b_bottom; int arr[320][6]; union regs i,o; /*

functions for mouse movement */

void showptr() { i.x.ax=1; int86(0x33,&i,&o); } int initmouse() { i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } void hide() { i.x.ax=2; int86(0x33,&i,&o); } void getbutton(int *button,int *x,int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.ax; *x=o.x.cx; *y=o.x.dx; } /*

code for moving brick through cursor

*/

void move_brick(int b_left,int b_top,int b_right,int b_bottom) { int button,x,y; getbutton(&button,&x,&y); x=b_left-x; b_left=b_left-x;

}

b_right=b_right-x; setcolor(12); rectangle(b_left,b_top,b_right,b_bottom); delay(1); setcolor(0); rectangle(b_left,b_top,b_right,b_bottom);

void draw_break() { for(count=0;count<320;count++) { setcolor(arr[count][1]); if(arr[count][0]!=0) rectangle(arr[count][2],arr[count][3],arr[count][4],arr[count][5]); } game=count; } void brick_break(int cx,int cy) { cx=cx-30; cy=cy-14; xp=cx/30; yp=cy/14; initial=19*(yp-1)+xp; if(initial<320 && cy<=225 && cx<=570) if(arr[initial][0]==1) { setcolor(0); score+=arr[initial][1]; rectangle(arr[initial][2],arr[initial][3],arr[initial][4],arr[initial][5]); game--; arr[initial][0]=0; if(incx==-1 && incy==-1) incy=1; else if(incx==-1 && incy==1) incx=1; else if(incx==1 && incy==1) incy=-1; else if(incx==1 && incy==-1) incx=-1; for(count=0;count<320;count++) { setcolor(arr[count][1]); if(arr[count][0]!=0) rectangle(arr[count][2],arr[count][3],arr[count][4],arr[count][5]); } } } void reflect() {

if(incx==-1 && incy==-1) incy=1; else if(incx==-1 && incy==1) incx=1; else if(incx==1 && incy==1) incy=-1; else if(incx==1 && incy==-1) incx=-1; } void check_cur(int cx,int cy) { width=15; setcolor(4); /*on right side checking*/ if(cx>=b_left+width && cx<=b_right && cy>=b_top-5) { incx=1; incy=-1; } /*on left side checking*/ else if(cx<=b_left+width && cx>=b_left && cy>=b_top-5) { incx=-1; incy=-1; } else if(cy>b_top) { flag=1; } } /*

main function

*/

int main(void) { int gdriver = detect, gmode, errorcode; initgraph(&gdriver, &gmode, "d:\\borlandc\\bgi"); errorcode = graphresult(); if (errorcode != grok) /* an error occurred */ { printf("graphics error: %s\n", grapherrormsg(errorcode)); printf("press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } if(initmouse()==0) { closegraph(); restorecrtmode(); printf("mouse driver not loaded"); } int midx = getmaxx() / 2;

int midy = getmaxy() / 2; int del=0; setbkcolor(8); for(int h=0;h<20;h++) { settextjustify(center_text, center_text); settextstyle(gothic_font, horiz_dir, 6); outtextxy(midx, midy-100, "break boll game"); settextstyle(triplex_font, horiz_dir, 1); outtextxy(midx+20,midy+20," amit gajjar"); settextstyle( sans_serif_font, horiz_dir, 1); outtextxy(400-(h*2),midy+100,"please wait..."); delay(100); setcolor(0); outtextxy(400-(h*2),midy+100,"please wait..."); setcolor(++del); line(200,190,450,190); } cleardevice(); left = 10; top = 10; right = 40; bottom = 24; int k; k=rand(); count=0; for(int i=0;i<16;i++) { for(int j=0;j<19;j++) { k=rand(); k=k%7; if(k==0) {k++;} setcolor(k); rectangle(left,top,right,bottom); arr[count][0]=1; arr[count][1]=k; arr[count][2]=left; arr[count][3]=top; arr[count][4]=right; arr[count][5]=bottom; count++; left=right+1; right=left+31; } left=10; top=bottom; right=40; bottom=top+14; } game=count; char key; int key_val;

int button,x,y; cx=getmaxx()/2; cy=getmaxy()-30; b_left=cx-10; b_top=getmaxy()-20; b_right=cx+20; b_bottom=getmaxy()-10; incx=incy=-1; while(!kbhit()) { setcolor(0); circle(cx,cy,5); cx=cx+incx; cy=cy+incy; if(cx<=20) reflect(); else if(cx>=getmaxx()-12) reflect(); else if(cy<=30) reflect(); else if(cy>=b_top-6) check_cur(cx,cy); //reflect(); if(flag==1) { cleardevice(); settextjustify(center_text, center_text); settextstyle(gothic_font, horiz_dir, 2); setcolor(20); outtextxy(midx, midy, "game over"); gotoxy(32,19); cout<<"your score is :"; cout<<score<<endl; if(game==0) { gotoxy(32,20); cout<<"win the match"; } else { gotoxy(32,20); cout<<"loss match"; } int col=0; while(!kbhit()) { delay(199); setcolor(++col); rectangle(210,230,430,260); }

} brick_break(cx,cy); setcolor(12); circle(cx,cy,5);

setcolor(0); circle(cx-incx,cy-incy,5); /* code for move brick and regenerate it */ getbutton(&button,&x,&y); x=b_left-x; b_left=b_left-x; b_right=b_right-x; setcolor(12); rectangle(b_left,b_top,b_right,b_bottom); delay(5); setcolor(0); rectangle(b_left,b_top,b_right,b_bottom);

} end:

if(game==0) { cleardevice(); gotoxy(32,13); cout<<"game over"<<endl; gotoxy(32,14); cout<<"win mathch"<<score<<endl; goto end; }

getch(); closegraph(); return 0;

}

Related Documents

Brick
November 2019 25
Brick Or
April 2020 18
Brick Walls
November 2019 19
Brick House.pdf
November 2019 28
Brick Script
December 2019 26
Brick Novella
December 2019 12