Java课程设计——大鱼吃小鱼(团队)

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界面优化不够,同时对于线程的运用不够熟练,没有用到线程池。

新的想法:针对这次课程设计,我们觉得可以增加用户信息存储功能、新模式新玩法的开发。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Java日期时间API系列31

  时间戳是指格林威治时间1970年01月01日00时00分00秒起至现在的总毫秒数,是所有时间的基础,其他时间可以通过时间戳转换得到。Java中本来已经有相关获取时间戳的方法,Java8后增加新的类Instant等专用于处理时间戳问题。 1获取时间戳的方法和性能对比1.1获取时间戳方法Java8以前

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0