推箱子 您所在的位置:网站首页 推箱子答案图解 推箱子

推箱子

2023-08-07 11:56| 来源: 网络整理| 查看: 265

推箱子 | 遇到的问题及解决的办法 ✨✨

在这里插入图片描述

文章目录 推箱子 | 遇到的问题及解决的办法 ✨✨玩游戏界面map数组的存储和读取怎么初始化map数组里面的内容怎么控制人物的移动怎么判断人物移动的模型怎么判断游戏结束地图编辑器的实现原理 创新问题JComboBox组件监听和游戏移动监听冲突实现音乐播放Timer类的使用

玩游戏界面 map数组的存储和读取

Q: map数组的存储和读取 A: 刚开始自己是想将map直接储存在 主程序里面。但是后来发现这种思维方式,并不适合大量的存储操作反而容易出错。后来刚好学到了文件流的操作,自己就想将map数组,先存储到每一个txt文件,在通过文件的读取操作,将txt里面的数据写入到每一个map数组里面,这样就实现了整个代码的健壮性。

1墙 0空地 4箱子 12有箱子的目的地 8空目的地 2玩家 在这里插入图片描述

源代码如下:

private void ReadMap(int k) throws IOException { DataInputStream cin = new DataInputStream(new FileInputStream("src/JavaClassDesign/"+k+".txt")); String b = ""; int j=0; while((b=cin.readLine())!=null) { char[] a=b.toCharArray(); for(int i=0;i if (num==boxnum){ Object[] options={"下一关","返回"}; int response=JOptionPane.showOptionDialog ( null, "你的选择","接下来",JOptionPane.YES_OPTION ,JOptionPane.PLAIN_MESSAGE, null, options, options[0] ) ; if(response==0) { if(musicFlag!=null) musicFlag.stop(); if(musicFlagtmp!=null) musicFlagtmp.stop(); this.dispose(); if(k String file; Clip clip; public ClipTestClass(String file) { this.file=file; } public void player() throws UnsupportedAudioFileException, IOException, LineUnavailableException { File filePath = new File(file); if(filePath.exists()) { AudioInputStream audioInput = AudioSystem.getAudioInputStream(filePath); clip = AudioSystem.getClip(); clip.open(audioInput); clip.start(); clip.loop(Clip.LOOP_CONTINUOUSLY); //Thread.sleep(Integer.MAX_VALUE); } } public void stop() { if(clip!=null) clip.stop(); } } Timer类的使用

Q:怎么使用Timer类的使用 A:使用System.currentTimeMillis()方法,获得时间,是long型是数值,数值是与1970年1月1日的差值。在用Data对象,获得当地时间

Timer time = new Timer(1000,new ActionListener() { public void actionPerformed(ActionEvent e) { long currentTime = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); Date date = new Date(currentTime); jl33.setText(formatter.format(date)); jl6.setText(String.valueOf((currentTime-currentTime1)/1000)+"秒"); } }); time.start();


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有