A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Thunder_-_Li 中级黑马   /  2013-9-22 20:09  /  1888 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

给大家分享一下捕鱼达人   简单制作   只为了 博得    加分啊   嘿嘿     源文件 3M  传不了  有需要的  联系啊:329246352   俺知道  低调 才是  
package fish;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Pool extends JPanel{
private BufferedImage background;
private Net net;
private Fish[] all;

public Pool() throws Exception {
  background = ImageIO.read(new File("bg.jpg"));
  net = new Net("net09.png");
  all = new Fish[]{
    new Fish("fish01"),new Fish("fish02"),
    new Fish("fish03"),new Fish("fish04"),
    new Fish("fish05"),new Fish("fish06"),
    new Fish("fish07"),new Fish("fish08"),
    new Fish("fish09"),new Fish("fish13"),
    new Fish("fish14"),new Fish("fish14")};
}

public void paint(Graphics g) {
  g.drawImage(background, 0,0,null);
  for (Fish fish: all) {
   int x = fish.getX();
   int y = fish.getY();
   g.drawImage(fish.getImage(), x, y, null);
  }
  if(net.isShow()){
   Image img = net.getImage();
   int x = net.getX() - net.getWidth()/2;
   int y = net.getY() - net.getHeight()/2;
   g.drawImage(img, x, y, null);
  }
}

public void action() throws Exception {
  //启动每条鱼,让鱼自己去游动(run)
  for (Fish fish : all) {
   //Thread 线程API, 可以启动鱼自己去游动
   Thread t = new Thread(fish);
   t.start();//启动(start)鱼自己去游动(run())
  }
  
  MouseAdapter l = new MouseAdapter(){
   public void mousePressed(MouseEvent e) {
    catchFish();//抓鱼
   }
   public void mouseMoved(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    net.setX(x);
    net.setY(y);
   }
   public void mouseEntered(MouseEvent e) {
    net.setShow(true);//Show 显示
   }
   public void mouseExited(MouseEvent e) {
    net.setShow(false);
   }
  };
  this.addMouseListener(l);
  this.addMouseMotionListener(l);
  
  while(true){
   repaint();//观察鱼去哪里了!
   Thread.sleep(1000/24);
  }
}

protected void catchFish() {
  for(int i=all.length-1; i>=0; i--){
   Fish fish = all[i];
   if(fish.catchBy(net)){
    fish.getOut();
    break;
   }
  }
}
public static void main(String[] args) throws Exception {
  JFrame frame = new JFrame("捞鱼");
  frame.setSize(800, 520);
  frame.setLocationRelativeTo(null);
  Pool pool = new Pool();
  frame.add(pool);
  frame.setVisible(true);
  pool.action();
}
}

QQ截图20130922200208.png (149.93 KB, 下载次数: 16)

截图啊

截图啊

评分

参与人数 1技术分 +1 收起 理由
乔兵 + 1 感谢分享!

查看全部评分

8 个回复

倒序浏览
果断顶起!
回复 使用道具 举报
楼主好厉害
回复 使用道具 举报
学习学习!
回复 使用道具 举报
654351471@qq.com
能否发到邮箱里
大神~
回复 使用道具 举报
好厉害,能给我也发一份吗?十分感谢!290250355@qq.com
回复 使用道具 举报
whj11 中级黑马 2013-9-23 23:14:34
7#
能给我来份吗,好厉害哟
回复 使用道具 举报
图像部分是什么做的?openGL?
回复 使用道具 举报
冯晓骏 发表于 2013-9-24 01:32
图像部分是什么做的?openGL?

看代码应该是图片的加载,包括大背景、网、鱼,然后线程控制其游动,捕捞。。。
顶一个!!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马