java弹球小游戏代码 java弹球小游戏实验报告( 二 )


int x=LB,y=UB;//定义坐标
int i=10000;//循环次数(自己选择跳出手段)
while(i0)
{
i--;
x=x+sh;
if(x=RB||x=LB) sh=-sh;//碰壁后步长变反
y=y+sz;
if(y=DB||y=UB) sz=-sz;//碰壁后步长变反
(显示代码)
}
return;
}
总得来说 , 就是相当于横向和纵向分别处理移动、反弹的问题,碰壁后步长变为相反数
不懂请追问
[求助]急求弹球游戏代码已使用TC2.0 IDE测试,正常运行java弹球小游戏代码:
引用:
#include "graphics.h"
#include "math.h"
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ESC 0x011b
int x,y,x1,y1,key,t1,t2,keyx,keylong,keymove,over=0,i,tt=0,fast;
int ballx[9]={53,103,263,120,236,390,410,450,600};
int bally[9]={158,239,120,113,30,313,120,263,231},ballz[9]={0};
float ls;
win()
{float lx,ly,ll;
for(i=0;i9;i++)
{
if(ballz==1)/*如果球体已经消失就不判断*/
continue;
lx=(float)(ballx-x);
ly=(float)bally-y;
ll=lx*lx+ly*ly;
ls=sqrt(ll);
if((int)ls17)/*判断两球是否碰到*/
{tt++;/*记录消失几个球*/
fast-=50;/*速度加快*/
if(i%2==0)/*移动加快*/
keymove+=5;
else
{
setcolor(0);
rectangle(keyx,460,keyx+keylong,470);
keylong-=10;/*长条变短*/
setcolor(YELLOW);
rectangle(keyx,460,keyx+keylong,470);
}
ballz=1;
setcolor(0);
circle(ballx,bally,10);
if(ybally)
if(xballx)
{t1=-1;t2=-1;}
else
{t1=1;t2=-1;}
else
if(xballx)
{t1=-1;t2=1;}
else
{t1=1;t2=1;}
}
}
}
fungo()
{ x=100,y=50,keyx=200,keylong=100,keymove=15,fast=600;
for(i=0;i9;i++)
{
setcolor(i+1);
circle(ballx,bally,10);
}
sleep(1);
t1=t2=1;
while(1)
{
while(!kbhit())
{
setcolor(YELLOW);
rectangle(keyx,460,keyx+keylong,470);
x1=x;
y1=y;
x+=t1;
y+=t2;
setcolor(4);
circle(x,y,6);
delay(fast);
setcolor(0);
circle(x,y,6);
win();
if(tt==9)/*胜利*/
{
cleardevice();
over=1;
setcolor(RED);
settextstyle(0,0,4);
setusercharsize(3,1,3,1);
outtextxy(200,200," YOU WIN! ");
break;
}
if(y480)/*失败*/
{
cleardevice();
over=1;
setcolor(RED);
settextstyle(0,0,4);
setusercharsize(3,1,3,1);
outtextxy(200,200,"GAME OVER");
break;
}
else if(x==11y==11)/*判断碰到东西*/
{t1=1;t2=1;}
else if(x==629y==11)
{t1=-1;t2=1;}
else if(x==11)
{
if(yy1)
{t1=1;t2=-1;}
else
{t1=1;t2=1;}
}
else if(y==11)
{
if(xx1)
{t1=-1;t2=1;}
else
{t1=1;t2=1;}
}
else if(x==629)
{
if(y1y)
{t1=-1;t2=-1;}
else
{t1=-1;t2=1;}
}
else if(y==449)
{
if(x=keyxx=keyx+keylong)
{
if(x(keyx+keylong/4))
{t1=-1;t2=-1;}
else if(x=(keyx+keylong/4)x(keyx+keylong/2))
{t1=-1;t2=-2;}
else if(x=(keyx+keylong/2)x(keyx+keylong/4*3))
{t1=1;t2=-2;}
else
{t1=1;t2=-1;}
}
}
}
if(over)
break;
key=bioskey(0);
setcolor(0);
rectangle(keyx,460,keyx+keylong,470);
if(key==ESC)
{cleardevice();break;}
else if(key==LEFT)
keyx-=keymove;
else if(key==RIGHT)
keyx+=keymove;
}
}
main()
{int gd=DETECT,gr;
initgraph(gd,gr,"c:\\tc");
fungo();
getch();
sleep(1);
closegraph();
}
Java程序解惑,希望大家帮帮忙,打砖块游戏不能用键盘控制 。开始和移动都不能 。运行是用application吗?import java.applet.Applet;

推荐阅读