1.团队名称、团员介绍
团队名称:三枪加一炮
赖富烨(组长):
Poison(毒药)类的设计;
FishJpanel(游戏面板)类中的线程、部分方法的实现;
林阿强(组员):
Login(简单登录界面)类的设计;
Playmusic(音乐播放)类的设计;
FishJframe(游戏容器)类的设计;
Bubble(气泡)类的设计;
张煌(组员):
OtherFish(系统鱼)类的设计;
OtherFishandbubble(系统鱼与气泡碰撞)类的设计;
FishJpanel(游戏面板)类中的线程、部分方法的实现;
2.项目Git地址(暂缺)
3.前期调查
 
通过对大鱼吃小鱼的调查,总结出我们设计需要涉及到鱼类的hp(生命值)、score(积分)等,碰撞检测,音乐设计等方面。
4.项目功能架构图、主要功能流程图
 
5.UML类图
 
6.项目运行截图或屏幕录制
 
7.项目关键代码
- 音乐播放
通过构造Playmusic类,编写播放背景音乐的相关方法,再通过Thread使GUI和Playmusic多个线程同时进行。
package fish;
import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JApplet;
 
import java.io.BufferedInputStream;import java.io.FileInputStream;
 import javazoom.jl.player.Player;
 /**
 * @author 林阿强
 * 2020-1-9
 */public class Playmusic {
 
    public Playmusic(String filename) {
        this.filename = filename;
    }
 
    public void play() {
        try {
            BufferedInputStream buffer = new BufferedInputStream(
                    new FileInputStream(filename));
            player = new Player(buffer);
            player.play();
        } catch (Exception e) {
            System.out.println(e);
        }
 
    }
 
    
 
    private String filename;
    private Player player;
 
}
----------------开启线程----------------------public void playmusic() {
        new Thread() {
            @Override
            public void run() {
                Playmusic mp3 = new Playmusic("music/music.wav");
                mp3.play();
            }
        }.start();
    }
- 碰撞的检测
碰撞检测是根据myFish的长宽与otherFish的长宽进行比较,其中是按照一定的数学公式(借鉴网上)来进行计算。计算完后,会对myFish的各个属性进行修改。
otherFish的长宽与bubble的长宽进行比较(无数学公式),碰撞后,bubble也会被otherFish吃掉,即图片消失。
注:图片的长宽皆是调用getHeight和getWidth方法获得。
-----------------------大鱼吃小鱼----------------------for (int i = 0; i < otherFishs.size(); i++) {
                        OtherFish otherFish = otherFishs.get(i);
                        if (myFishX < otherFish.oImg.getWidth(null) * 0.7 + otherFish.x
                                && myFishY < otherFish.oImg.getHeight(null) * 0.7 + otherFish.y
                                && myFishX + myFishW > otherFish.x + otherFish.oImg.getWidth(null) * 0.3
                                && myFishY + myFishH > otherFish.y + otherFish.oImg.getHeight(null) * 0.3
                                || myFishX < otherFish.x + otherFish.oImg.getWidth(null) * 0.7
                                        && myFishY < otherFish.y + otherFish.oImg.getHeight(null) * 0.7
                                        && myFishX + myFishW > otherFish.x + otherFish.oImg.getWidth(null) * 0.3
                                        && myFishY + myFishH > otherFish.y + myFishY * 0.3) {
                            if (otherFish.oImg.getHeight(null) < myFishH) {
                                otherFishs.remove(i);
                                myFishW += 6;
                                myFishH += 6;
                                score = score + 3;
                                break;
                            }
                            if (otherFish.oImg.getHeight(null) > myFishH) {
                                hp--;
                                if (hp > 0) {
                                    bubbles.clear();
                                    poisons.clear();
                                    otherFishs.clear();
                                    myFishW = 30;
                                    myFishH = 20;
                                } else {
                                    flag = 1;
                                    myImg = new ImageIcon("picture/wu.png").getImage();
                                }
                            }
                        }
                    }
----------其他鱼和气泡--------
public class OtherFishandbubble {
  public int fishMeet(OtherFish otherFish,Bubble bubble){
      int i=0;
      if(otherFish.x<bubble.qpImg.getWidth(null)+bubble.x&&otherFish.y<bubble.qpImg.getHeight(null)+bubble.y&&otherFish.x+otherFish.oImg.getWidth(null)>bubble.x&&otherFish.y+otherFish.oImg.getHeight(null)>bubble.y){
          i=1;
      }
      
      return i;
  }
}
8.代码静态扫描
- 第一次扫描

- 最终扫描

9.尚待改进或者新的想法
不足:功能不够完善,GUI界面优化不够,同时对于线程的运用不够熟练,没有用到线程池。
新的想法:针对这次课程设计,我们觉得可以增加用户信息存储功能、新模式新玩法的开发。
 
  
  
  
 
 
  
 
 
 