1.团队名称、团员介绍
团队名称:三枪加一炮
赖富烨(组长):
Poison(毒药)类的设计;
FishJpanel(游戏面板)类中的线程、部分方法的实现;
林阿强(组员):
Login(简单登录界面)类的设计;
Playmusic(音乐播放)类的设计;
FishJframe(游戏容器)类的设计;
Bubble(气泡)类的设计;
张煌(组员):
OtherFish(系统鱼)类的设计;
OtherFishandbubble(系统鱼与气泡碰撞)类的设计;
FishJpanel(游戏面板)类中的线程、部分方法的实现;
2.项目Git地址(暂缺)
3.前期调查

通过对大鱼吃小鱼的调查,总结出我们设计需要涉及到鱼类的hp(生命值)、score(积分)等,碰撞检测,音乐设计等方面。
4.项目功能架构图、主要功能流程图

5.UML类图

6.项目运行截图或屏幕录制

7.项目关键代码
- 音乐播放
通过构造Playmusic类,编写播放背景音乐的相关方法,再通过Thread使GUI和Playmusic多个线程同时进行。
1package fish; 2import java.applet.AudioClip; 3import java.net.MalformedURLException; 4import java.net.URL; 5import javax.swing.JApplet; 6 7 8import java.io.BufferedInputStream;import java.io.FileInputStream; 9 import javazoom.jl.player.Player; 10 /** 11 * @author 林阿强 12 * 2020-1-9 13 */public class Playmusic { 14 15 public Playmusic(String filename) { 16 this.filename = filename; 17 } 18 19 public void play() { 20 try { 21 BufferedInputStream buffer = new BufferedInputStream( 22 new FileInputStream(filename)); 23 player = new Player(buffer); 24 player.play(); 25 } catch (Exception e) { 26 System.out.println(e); 27 } 28 29 } 30 31 32 33 private String filename; 34 private Player player; 35 36} 37 38----------------开启线程----------------------public void playmusic() { 39 new Thread() { 40 @Override 41 public void run() { 42 Playmusic mp3 = new Playmusic("music/music.wav"); 43 mp3.play(); 44 } 45 }.start(); 46 }
- 碰撞的检测
碰撞检测是根据myFish的长宽与otherFish的长宽进行比较,其中是按照一定的数学公式(借鉴网上)来进行计算。计算完后,会对myFish的各个属性进行修改。
otherFish的长宽与bubble的长宽进行比较(无数学公式),碰撞后,bubble也会被otherFish吃掉,即图片消失。
注:图片的长宽皆是调用getHeight和getWidth方法获得。
1-----------------------大鱼吃小鱼----------------------for (int i = 0; i < otherFishs.size(); i++) { 2 OtherFish otherFish = otherFishs.get(i); 3 if (myFishX < otherFish.oImg.getWidth(null) * 0.7 + otherFish.x 4 && myFishY < otherFish.oImg.getHeight(null) * 0.7 + otherFish.y 5 && myFishX + myFishW > otherFish.x + otherFish.oImg.getWidth(null) * 0.3 6 && myFishY + myFishH > otherFish.y + otherFish.oImg.getHeight(null) * 0.3 7 || myFishX < otherFish.x + otherFish.oImg.getWidth(null) * 0.7 8 && myFishY < otherFish.y + otherFish.oImg.getHeight(null) * 0.7 9 && myFishX + myFishW > otherFish.x + otherFish.oImg.getWidth(null) * 0.3 10 && myFishY + myFishH > otherFish.y + myFishY * 0.3) { 11 if (otherFish.oImg.getHeight(null) < myFishH) { 12 otherFishs.remove(i); 13 myFishW += 6; 14 myFishH += 6; 15 score = score + 3; 16 break; 17 } 18 if (otherFish.oImg.getHeight(null) > myFishH) { 19 hp--; 20 if (hp > 0) { 21 bubbles.clear(); 22 poisons.clear(); 23 otherFishs.clear(); 24 myFishW = 30; 25 myFishH = 20; 26 } else { 27 flag = 1; 28 myImg = new ImageIcon("picture/wu.png").getImage(); 29 } 30 31 } 32 } 33 } 34 35----------其他鱼和气泡-------- 36public class OtherFishandbubble { 37 public int fishMeet(OtherFish otherFish,Bubble bubble){ 38 int i=0; 39 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){ 40 i=1; 41 } 42 43 return i; 44 } 45}
8.代码静态扫描
- 第一次扫描

- 最终扫描

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