开发工具eclipse,jdk1.8
文档截图:
java
package com.qd.fish;
import java.awt.Graphics;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
public class Fishes {
//定义一个集合来管理鱼
List<Fish> fishes=new ArrayList<>();
//定义鱼群的帧数数组
int[] fishNum={8,8,8,8,8,10,10,12,12,12,12,12};
//定义不同鱼的宽高数组
int[][] fishSize={
{55,296/8},{78,512/8},{72,448/8},
{77,472/8},{107,976/8},{92,1510/10},
{178,1870/10},{105,948/12},{174,1512/12},
{166,2196/12},{509,3240/12},{516,3276/12}
};
//定义一个不同鱼的概率数组
int[] rate={2,3,4,5,6,7,8,9,10,11,15,20};
//定义渔场对象
FishPool fp;
//定义分值数组
int[] point={2,3,8,15,20,40,50,60,100,120,150,200};
public Fishes(FishPool fp){
this.fp=fp;
addFish();
}
public void addFish(){
try {
for(int i=1;i<=12;i++){
Fish fish=new Fish(
ImageIO.read(
new File("images/fish"+i+".png")),
fishNum[i-1],
fishSize[i-1][0],
fishSize[i-1][1],
rate[i-1],point[i-1]
);
fishes.add(fish);
}
} catch (Exception e) {
}
}
public void move(){
for(int i=0;i<fishes.size();i++){
fishes.get(i).move();
}
}
public void draw(Graphics g){
for(int i=0;i<fishes.size();i++){
Fish fish=fishes.get(i);
fish.draw(g);
//判断被捕捉并且已播放完被捕捉动画,删除
if(fish.isCatch&&
fish.frameIndex>=fish.num){
fishes.remove(fish);
//创建金币
Money money=new Money(
fish.x, fish.y, fp);
fp.moneys.add(money);
//加分
fp.point=fp.point+fish.point;
//如果渔场中的鱼少于5条,再次初始化鱼群
if(fishes.size()<5){
addFish();
}
}
}
}
}