捕鱼达人实验报告.docx

上传人:b****4 文档编号:24641315 上传时间:2023-05-29 格式:DOCX 页数:8 大小:62.07KB
下载 相关 举报
捕鱼达人实验报告.docx_第1页
第1页 / 共8页
捕鱼达人实验报告.docx_第2页
第2页 / 共8页
捕鱼达人实验报告.docx_第3页
第3页 / 共8页
捕鱼达人实验报告.docx_第4页
第4页 / 共8页
捕鱼达人实验报告.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

捕鱼达人实验报告.docx

《捕鱼达人实验报告.docx》由会员分享,可在线阅读,更多相关《捕鱼达人实验报告.docx(8页珍藏版)》请在冰豆网上搜索。

捕鱼达人实验报告.docx

捕鱼达人实验报告

山西财经大学《JAVA实用教程》实验报告

年月日

实验题目

捕鱼达人

选课课号

学院

班级

姓名

学号

理论课教师

上机指导教师

实验目的及要求:

捕鱼达人游戏的要求:

1.在鱼池有很多鱼且鱼各自游动

2.有一张渔网,随鼠标移动点击鼠标即可抓住渔网中的与

3.抓到鱼进行积分

实验原理、详细操作步骤及程序代码:

1.理清对象之间的数据关系。

对象:

窗口鱼池,多条鱼,渔网;

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("fish0"+(i+1));

}

allfish[allfish.length-2]=newFish("fish13");

allfish[allfish.length-1]=newFish("fish14");

net=newNet();

score=0;

}

publicvoidaction()throwsInterruptedException{

for(inti=0;i

allfish[i].start();

}

MouseAdapterl=newMouseAdapter(){

publicvoidmouseEntered(MouseEvente){

net.show=true;

}

publicvoidmousePressed(MouseEvente){

for(inti=0;i

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);

for(inti=0;i

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{

intx;

inty;

intheight;

intwidth;

BufferedImageimage;

BufferedImage[]images;

intindex;

intstep;

publicFish(Stringpre)throwsException{

images=newBufferedImage[10];

for(inti=0;i<9;i++){

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(){

while(true){

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&&dx0&&dy

}

}

 

组内分工(可选)

实验中发现的问题及解决方法、实验运行效果:

心得体会

教师评语

 

成绩

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1