教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 资格考试 >

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

来源:网络收集 时间:2026-07-17
导读: if((x1>x2)((x1-x2)>Math.abs(y2-y1))) { option=1;//移动的方向向左 System.out.println(\向左方向移动\ } if((x1 Math.abs(y2-y1))) { option=2;//移动的方向向右 System.out.println(\向右方向移动\ } if((y1>y2

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

…… 此处隐藏:1362字,全部文档内容请下载后查看。喜欢就下载吧 ……
2048小游戏 Java 课程设计报告书(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/413287.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)