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界面優化不夠,同時對於線程的運用不夠熟練,沒有用到線程池。
新的想法:針對這次課程設計,我們覺得可以增加用戶信息存儲功能、新模式新玩法的開發。