Beruflich Dokumente
Kultur Dokumente
*/
#include<iostream.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#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;
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;
}
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;
}
rectangle(arr[initial][2],arr[initial][3],arr[initial][4],arr[initial][5]);
game--;
arr[initial][0]=0;
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;
}
/* main function */
int main(void)
{
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");
}
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);
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);
if(game==0)
{
cleardevice();
gotoxy(32,13);
cout<<"game over"<<endl;
gotoxy(32,14);
cout<<"win mathch"<<score<<endl;
goto end;
}
}
end:
getch();
closegraph();
return 0;
}