捕鱼达人实验报告Word格式.docx
- 文档编号:3769669
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:8
- 大小:31.45KB
捕鱼达人实验报告Word格式.docx
《捕鱼达人实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《捕鱼达人实验报告Word格式.docx(8页珍藏版)》请在冰点文库上搜索。
对象:
窗口鱼池,多条鱼,渔网;
2.数据模型:
鱼和渔网的width,height,x,y;
3.类的设计
4.程序代码:
importjava.awt.*;
importjava.awt.event.*;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjavax.imageio.ImageIO;
importjavax.swing.*;
importjava.util.Random;
publicclassFishDemoextendsThread{
publicstaticvoidmain(String[]args)throwsException{
FishDemofish=newFishDemo();
fish.start();
}
publicvoidrun(){
JFrameframe=newJFrame("
捕鱼达人"
);
Poolpool;
try{
pool=newPool();
frame.add(pool);
frame.setSize(800,510);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
pool.action();
}catch(Exceptione){
e.printStackTrace();
}
classPoolextendsJPanel{
BufferedImagebg;
Fish[]allfish;
Netnet;
intscore;
publicPool()throwsException{
bg=ImageIO.read(newFile("
bg.jpg"
));
allfish=newFish[9+2+9];
for(inti=0;
i<
9;
i++){
allfish[i]=newFish("
fish0"
+(i+1));
allfish[i+9]=newFish("
}
allfish[allfish.length-2]=newFish("
fish13"
allfish[allfish.length-1]=newFish("
fish14"
net=newNet();
score=0;
publicvoidaction()throwsInterruptedException{
allfish.length;
allfish[i].start();
MouseAdapterl=newMouseAdapter(){
publicvoidmouseEntered(MouseEvente){
net.show=true;
}
publicvoidmousePressed(MouseEvente){
for(inti=0;
Fishfish=allfish[i];
if(fish.catain(net.x,net.y)){
fish.catchFish();
score+=fish.width/10;
}
}
publicvoidmouseMoved(MouseEvente){
intx=e.getX();
inty=e.getY();
net.x=x;
net.y=y;
publicvoidmouseExited(MouseEvente){
net.show=false;
};
this.addMouseListener(l);
this.addMouseMotionListener(l);
while(true){
repaint();
Thread.sleep(1000/24);
publicvoidpaint(Graphicsg){
g.drawImage(bg,0,0,null);
Fishfish=allfish[i];
g.drawImage(fish.image,fish.x,fish.y,null);
if(net.show){
g.drawImage(net.image,net.x-net.width/2,net.y-net.height/2,null);
g.setColor(Color.white);
g.setFont(newFont("
黑体"
Font.BOLD,15));
g.drawString("
得分:
"
+score,10,20);
classNet{
intx;
inty;
intwidth;
intheight;
booleanshow;
BufferedImageimage;
publicNet()throwsException{
image=ImageIO.read(newFile("
net09.png"
width=image.getWidth();
height=image.getHeight();
x=0;
y=0;
show=false;
classFishextendsThread{
BufferedImage[]images;
intindex;
intstep;
publicFish(Stringpre)throwsException{
images=newBufferedImage[10];
Stringfilename=pre+"
_0"
+(i+1)+"
.png"
;
images[i]=ImageIO.read(newFile(filename));
System.out.println(filename);
images[9]=ImageIO.read(newFile(pre+"
_10.png"
image=images[0];
width=image.getWidth();
height=image.getHeight();
Randomrandom=newRandom();
x=random.nextInt(800-width);
y=random.nextInt(480-height);
step=random.nextInt(3)+1;
publicvoidrun(){
x-=step;
if(x<
-width){
getout();
index++;
image=images[index%images.length];
if(index==100){index=0;
try{
Thread.sleep(1000/24);
}catch(InterruptedExceptione){
e.printStackTrace();
publicvoidgetout(){
x=800;
Randomr=newRandom();
y=r.nextInt(480-height);
step=r.nextInt(3)+1;
publicvoidcatchFish(){
getout();
publicbooleancatain(intx2,inty2){
intdx=x2-x;
intdy=y2-y;
returndx>
0&
&
dx<
width&
dy>
dy<
height;
组内分工(可选)
实验中发现的问题及解决方法、实验运行效果:
心得体会
教师评语
成绩
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 捕鱼 实验 报告