主题:turboc2.0下的[是男人就点100下]
考完试了,哈哈。贴个刚做的东西。Gamespeed 可以在1-3之间,不然就变态了。另外分数的显示会左右晃,如果觉得不爽,就自己动手改吧。
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<math.h>
#define Timer 0x1c
#define Gamespeed 2
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
typedef enum boolean{False,True}BOOLEAN;
int TimerCounter=0;
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt newhandler(__CPPARGS){
TimerCounter++;
oldhandler();
}
void SetTimer(void interrupt(*IntProc)(__CPPARGS)){
oldhandler=getvect(Timer);
disable();
setvect(Timer,IntProc);
enable();
}
void CloseTimer(){
disable();
setvect(Timer,oldhandler);
enable();
}
void mshow(){
union REGS ireg,oreg;
ireg.x.ax=1;
int86(0x33,&ireg,&oreg);
}
void mhide(){
union REGS ireg,oreg;
ireg.x.ax=2;
int86(0x33,&ireg,&oreg);
}
void getmxy(int *x,int *y){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
*x=oreg.x.cx;
*y=oreg.x.dx;
}
BOOLEAN leftbtnp(){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
if(oreg.x.bx & 1)
return True;
else
return False;
}
void printbg(){
setcolor(10);
rectangle(10,0,630,349);
rectangle(70,40,570,300);
line(10,0,70,40);
line(630,0,570,40);
line(630,349,570,300);
line(10,349,70,300);
}
void printball(int x,int y,int c){
setcolor(c);
setfillstyle(7,c);
pieslice(x,y,0,360,30);
}
void printm(int x,int y){
setcolor(15);
circle(x,y,5);
}
void prints(char *s,char *sh,BOOLEAN sc){
setcolor(9);
outtextxy(sc?20:580,200,s);
outtextxy(sc?100:500,15,sh);
}
int main(void){
int gdriver=EGA,gmode=EGAHI;
double px=320,py=295,vx=0,vy=0;
int curpage=0,score=0,hiscore=0;
int mx,my,bc=4;
char str[3]="0",strh[3]="0";
BOOLEAN onland=True,onright=True,mpressed=False;
initgraph(&gdriver,&gmode,"d:\\software\\turboc2");
setbkcolor(0);
settextstyle(0,0,2);
SetTimer(newhandler);
mshow();
while(1){
if(kbhit())break;
if(TimerCounter>0){
TimerCounter=0;
getmxy(&mx,&my);
curpage=curpage==0?1:0;
setactivepage(curpage);
cleardevice();
printbg();
onright=(px<320)?False:True;
prints(str,strh,onright);
printball((int)px,(int)py,bc);
printm(mx,my);
setvisualpage(curpage);
if(onland==False && fabs(py-295)<1 && fabs(vy)<Gamespeed){
onland=True;
py=295;
vy=0;
}
if(onland){
px+=vx;
vx*=0.97;
}
else{
px+=vx;
vy=vy*0.97+Gamespeed-0.5;
py+=vy;
vx*=0.97;
}
if(py<50 && vy<0){
py=50;
vy=-vy;
}
if(py>295 && vy>0){
py=295;
vy=-vy;
if(score>hiscore){
hiscore=score;
sprintf(strh,"%d",hiscore);
}
score=0;
sprintf(str,"%d",score);
}
if(px<70 && vx<0){
px=70;
vx=-vx;
}
if(px>570 && vx>0){
px=570;
vx=-vx;
}
if(leftbtnp()){
if(!mpressed){
if((pow((px-mx),2)+pow((py-my),2))<900.0){
vx=(px-mx)*Gamespeed;
if((my-py)<10)
vy=-10*Gamespeed;
else
vy=(py-my)*Gamespeed;
score++;
sprintf(str,"%d",score);
bc++;
if(bc==16)bc=1;
mpressed=True;
onland=False;
}
}
}
else
mpressed=False;
}
}
mhide();
CloseTimer();
closegraph();
return 0;
}
希望大家提出意见,谢谢。
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<math.h>
#define Timer 0x1c
#define Gamespeed 2
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
typedef enum boolean{False,True}BOOLEAN;
int TimerCounter=0;
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt newhandler(__CPPARGS){
TimerCounter++;
oldhandler();
}
void SetTimer(void interrupt(*IntProc)(__CPPARGS)){
oldhandler=getvect(Timer);
disable();
setvect(Timer,IntProc);
enable();
}
void CloseTimer(){
disable();
setvect(Timer,oldhandler);
enable();
}
void mshow(){
union REGS ireg,oreg;
ireg.x.ax=1;
int86(0x33,&ireg,&oreg);
}
void mhide(){
union REGS ireg,oreg;
ireg.x.ax=2;
int86(0x33,&ireg,&oreg);
}
void getmxy(int *x,int *y){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
*x=oreg.x.cx;
*y=oreg.x.dx;
}
BOOLEAN leftbtnp(){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
if(oreg.x.bx & 1)
return True;
else
return False;
}
void printbg(){
setcolor(10);
rectangle(10,0,630,349);
rectangle(70,40,570,300);
line(10,0,70,40);
line(630,0,570,40);
line(630,349,570,300);
line(10,349,70,300);
}
void printball(int x,int y,int c){
setcolor(c);
setfillstyle(7,c);
pieslice(x,y,0,360,30);
}
void printm(int x,int y){
setcolor(15);
circle(x,y,5);
}
void prints(char *s,char *sh,BOOLEAN sc){
setcolor(9);
outtextxy(sc?20:580,200,s);
outtextxy(sc?100:500,15,sh);
}
int main(void){
int gdriver=EGA,gmode=EGAHI;
double px=320,py=295,vx=0,vy=0;
int curpage=0,score=0,hiscore=0;
int mx,my,bc=4;
char str[3]="0",strh[3]="0";
BOOLEAN onland=True,onright=True,mpressed=False;
initgraph(&gdriver,&gmode,"d:\\software\\turboc2");
setbkcolor(0);
settextstyle(0,0,2);
SetTimer(newhandler);
mshow();
while(1){
if(kbhit())break;
if(TimerCounter>0){
TimerCounter=0;
getmxy(&mx,&my);
curpage=curpage==0?1:0;
setactivepage(curpage);
cleardevice();
printbg();
onright=(px<320)?False:True;
prints(str,strh,onright);
printball((int)px,(int)py,bc);
printm(mx,my);
setvisualpage(curpage);
if(onland==False && fabs(py-295)<1 && fabs(vy)<Gamespeed){
onland=True;
py=295;
vy=0;
}
if(onland){
px+=vx;
vx*=0.97;
}
else{
px+=vx;
vy=vy*0.97+Gamespeed-0.5;
py+=vy;
vx*=0.97;
}
if(py<50 && vy<0){
py=50;
vy=-vy;
}
if(py>295 && vy>0){
py=295;
vy=-vy;
if(score>hiscore){
hiscore=score;
sprintf(strh,"%d",hiscore);
}
score=0;
sprintf(str,"%d",score);
}
if(px<70 && vx<0){
px=70;
vx=-vx;
}
if(px>570 && vx>0){
px=570;
vx=-vx;
}
if(leftbtnp()){
if(!mpressed){
if((pow((px-mx),2)+pow((py-my),2))<900.0){
vx=(px-mx)*Gamespeed;
if((my-py)<10)
vy=-10*Gamespeed;
else
vy=(py-my)*Gamespeed;
score++;
sprintf(str,"%d",score);
bc++;
if(bc==16)bc=1;
mpressed=True;
onland=False;
}
}
}
else
mpressed=False;
}
}
mhide();
CloseTimer();
closegraph();
return 0;
}
希望大家提出意见,谢谢。