推箱子 | 您所在的位置:网站首页 › 推箱子答案图解 › 推箱子 |
推箱子 | 遇到的问题及解决的办法 ✨✨
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 实验室设备网 版权所有 |