黑马程序员技术交流社区

标题: 分享捕鱼joy [打印本页]

作者: Thunder_-_Li    时间: 2013-9-22 20:09
标题: 分享捕鱼joy
给大家分享一下捕鱼达人   简单制作   只为了 博得    加分啊   嘿嘿     源文件 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, 下载次数: 31)

截图啊

截图啊

作者: 黄文伯    时间: 2013-9-22 21:05
果断顶起!
作者: 王涵    时间: 2013-9-23 09:12
楼主好厉害
作者: 小风๑吹吹‵o    时间: 2013-9-23 18:18
654351471@qq.com
能否发到邮箱里
大神~
作者: 艾萱    时间: 2013-9-23 18:51
好厉害,能给我也发一份吗?十分感谢!290250355@qq.com
作者: whj11    时间: 2013-9-23 23:14
能给我来份吗,好厉害哟
作者: 冯晓骏    时间: 2013-9-24 01:32
图像部分是什么做的?openGL?
作者: 张云飞    时间: 2013-9-24 11:13
冯晓骏 发表于 2013-9-24 01:32
图像部分是什么做的?openGL?

看代码应该是图片的加载,包括大背景、网、鱼,然后线程控制其游动,捕捞。。。
顶一个!!!





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2