2048小游戏 Java 课程设计报告书(6)

2019-08-03 10:09

if((x1>x2)&&((x1-x2)>Math.abs(y2-y1))) { option=1;//移动的方向向左 System.out.println(\向左方向移动\ } if((x1Math.abs(y2-y1))) { option=2;//移动的方向向右 System.out.println(\向右方向移动\ } if((y1>y2)&&((y1-y2)>Math.abs(x1-x2))) { option=3;//移动的方向向上 System.out.println(\向上方向移动\ } if((y1Math.abs(x1-x2))) { option=4;//移动的方向向下 System.out.println(\向下方向移动\ } //将上一次的鼠标位置清零 this.x1=0; this.y1=0; this.x2=0; this.y2=0; do_label_keyPressed(option); } }

public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub do_label_keyPressed(e);// 调用处理方法 }

public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getActionCommand().equals(\ { if(jb1_flag2) { setJb1_flag(false); jb1_flag2=false; jb1.setIcon(new ImageIcon(\静音图标.jpg\ jb1.requestFocus(false);//让按钮失去焦点

24

} else { setJb1_flag(true); jb1_flag2=true; jb1.setIcon(new ImageIcon(\声音图标.jpg\ jb1.requestFocus(false);//让按钮失去焦点 } jb1.setFocusable(false);//设置焦点,不能用请求焦点 } } }

//记录类

class Recorder { //定义一个变量记录最高分 private static int maxscores_2048=0; public static int getMaxscores_2048() { return maxscores_2048; } public static void setMaxscores_2048(int maxscores_2048) { Recorder.maxscores_2048 = maxscores_2048; } //定义文件输入流变量 private static FileReader fr=null; private static BufferedReader br=null; private static FileWriter fw=null; private static BufferedWriter bw=null; //从文件中读取,记录 public static void getRecording() { boolean flag=false;//用于判断文件是否是新创建的 try { File f=new File(\ if(f.exists()) { fr=new FileReader(f); br=new BufferedReader(fr); String n=br.readLine(); maxscores_2048=Integer.parseInt(n); } else { flag=f.createNewFile();

25

} } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { try { //关闭文件流的顺序,先开的后关闭 if(!flag) { br.close(); fr.close(); } } catch (Exception e2) { // TODO: handle exception e2.printStackTrace(); } } }

//保存最高分纪录

public static void keepRecording() { //创建 try { File f=new File(\ fw=new FileWriter(f); bw=new BufferedWriter(fw); bw.write(maxscores_2048+\ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { //关闭流 try { bw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

26

} }

//播放声音的类

class AePlayWave extends Thread { private static String filename; public AePlayWave(String wavefile) { filename=wavefile; } public AePlayWave() {} public void run() { while(true) { File soundFile=new File(filename); AudioInputStream audioInputStream=null; try { audioInputStream=AudioSystem.getAudioInputStream(soundFile); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ; } AudioFormat format=audioInputStream.getFormat(); SourceDataLine auline=null; DataLine.Info info=new DataLine.Info(SourceDataLine.class, format); try { auline=(SourceDataLine)AudioSystem.getLine(info); auline.open(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ; } auline.start(); int nBytesRead=0; byte[]abData=new byte[1024]; try { while(nBytesRead!=-1) { nBytesRead=audioInputStream.read(abData); if(MyPanel.isJb1_flag())

27

{ if(nBytesRead>=0) }

}

}

{ auline.write(abData,0,nBytesRead); } } else { while(!MyPanel.isJb1_flag()); } }

} catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ; }

finally { auline.drain(); auline.close(); }

28


2048小游戏 Java 课程设计报告书(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:医院揭牌仪式主持词范本

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: