ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:17.34KB ,
资源ID:22531986      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/22531986.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(贪吃蛇游戏代码Word格式文档下载.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

贪吃蛇游戏代码Word格式文档下载.docx

1、存盘退出 jmi3.addActionListener(this); jmi5=new JMenuItem(接着上一次玩 jmi5.addActionListener(this); jmi4=new JMenuItem(退出 jmi4.addActionListener(this); jp=new JPanel() public void paint(Graphics g) g.setFont(new Font(宋体,Font.BOLD,40); g.drawString(play, 250, 200); ; jm1.add(jmi6); jm1.add(jmi1); jm1.add(jmi2

2、); jm1.add(jmi3); jm1.add(jmi5); jm1.add(jmi4); jmb.add(jm1); this.setJMenuBar(jmb); this.add(jp); this.setSize(650,500); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void actionPerformed(ActionEvent e) if(e.getSource()=jmi6) System.out.println(ok wp=new Wormpane

3、l(); this.addKeyListener(wp); this.add(wp); if(e.getSource()=jmi4) System.exit(0); if(e.getSource()=jmi2) this.wp.setSpeed(0); if(e.getSource()=jmi1) this.wp.setSpeed(1); if(e.getSource()=jmi3) ArrayList al=this.wp.vp; FileWriter fw=null; BufferedWriter bw=null; try fw=new FileWriter(D:/Recording.tx

4、t bw=new BufferedWriter(fw); for(int i=0;ial.size();i+) Wormpoint wm=al.get(i); if(i=0) int dire=wm.getDirestion(); bw.write(dire+rn int x=wm.getX(); int y=wm.getY(); bw.write(x+ +y+ catch (IOException args) args.printStackTrace(); finally try bw.flush(); bw.close(); fw.close(); System.exit(0); catc

5、h (IOException args) args.printStackTrace(); if(e.getSource()=jmi5) wp=new Wormpanel(); al=new ArrayList(); FileReader fr=null; BufferedReader br=null; fr=new FileReader( br=new BufferedReader(fr); String st; st=br.readLine(); Wormpoint head=new Wormpoint(); head.setDirestion(Integer.parseInt(st); S

6、tring shead=st.split( head.setX(Integer.parseInt(shead0); head.setY(Integer.parseInt(shead1); al.add(head); while(st=br.readLine()!=null) Wormpoint wm=new Wormpoint(); String str=st.split( wm.setX(Integer.parseInt(str0); wm.setY(Integer.parseInt(str1); al.add(wm); this.wp.vp=al; br.close(); fr.close

7、();/面板类 进行界面操作import java.awt.List;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.util.*;import java.util.Timer;public class Wormpanel extends JPanel implements KeyListener ArrayList vp=new ArrayList Wormpoint point; Wormpoint wp; String reco; int speed; boolean ismove=

8、true; Recorder recor; public int getSpeed() return speed; public void setSpeed(int speed) this.speed = speed; public Wormpanel() speed=1; recor=new Recorder(); recor.filereader(); reco=recor.recorder; point=new Wormpoint(); point.setWidth(10); point.setX(int)(Math.random()*450); point.setY(int)(Math

9、.random()*380); for(int i=0;Wormpoint.length; wp=new Wormpoint(); wp.setX(20); wp.setY(20-wp.getWidth(); vp.add(wp); Timer t=new Timer(); t.schedule(new Mytask(), 0,100); public void touch() boolean b=false; Wormpoint w=vp.get(0); switch(w.getDirestion() case 1: if(w.getX()point.getX()|(w.getX()+w.g

10、etWidth()point.getX() if(w.getY()point.getY() System.out.print(touch ismove=false; point=new Wormpoint(); point.setWidth(10); point.setX(int)(Math.random()*450); point.setY(int)(Math.random()*380); Wormpoint.length+; recor.cadd(); if(recor.getcount()*10Integer.parseInt(reco) recor.filewriter(); brea

11、k; case 2: if(w.getX() if(w.getY()+w.getWidth() point=new Wormpoint(); point.setWidth(10); point.setX(int)(Math.random()*450); point.setY(int)(Math.random()*380); Wormpoint.length+; recor.cadd(); if(recor.getcount()*10 recor.filewriter(); case 3: if(w.getY()point.getY()&w.getY()w.getY()+w.getWidth()

12、point.getX()&w.getX() if(w.getX()+w.getWidth()w.getX()+w.getWidth() public void paint(Graphics g) super.paint(g); g.fillRect(0, 0,450, 400); g.setColor(Color.cyan); if(!point.isIseate() g.fillOval(point.getX(), point.getY(), point.getWidth(), point.getWidth(); g.setColor(Color.DARK_GRAY); g.setFont(

13、new Font(,Font.BOLD,20); g.drawString(我的得分:+recor.getcount()*10, 460, 50);我的记录:+reco, 460, 80); Wormpoint w;vp.size(); w= vp.get(i); g.setColor(Color.red); g.fill3DRect(w.getX(), w.getY(), w.getWidth(),w.getWidth() ,false); g.setColor(Color.black); g.drawRect(w.getX(), w.getY(), w.getWidth(),w.getWi

14、dth() ); class Mytask extends TimerTask public void run() Wormpoint w=vp.get(0); Wormpoint xin=new Wormpoint(); int direct=w.getDirestion(); switch(direct) case 1: xin.setX(w.getX(); xin.setDirestion(w.getDirestion(); xin.setY(w.getY()-w.getWidth()*speed); if(xin.getY()=400) xin.setY(0); /down case

15、3: xin.setX(w.getX()-w.getWidth()*speed); xin.setY(w.getY(); if(xin.getX()=450) xin.setX(0); /right vp.add(0,xin); touch(); if(ismove&speed! vp.remove(vp.size()-1); ismove=true; repaint();public void keyPressed(KeyEvent e) if(e.getKeyCode()=e.VK_UP) vp.get(0).setDirestion(1); if(e.getKeyCode()=e.VK_

16、DOWN) vp.get(0).setDirestion(2);/down if(e.getKeyCode()=e.VK_LEFT) vp.get(0).setDirestion(3);/left if(e.getKeyCode()=e.VK_RIGHT) vp.get(0).setDirestion(4);public void keyReleased(KeyEvent e) / TODO Auto-generated method stubpublic void keyTyped(KeyEvent e) /单元类public class Wormpoint private int x; p

17、rivate int y; private int direstion=2; static int length=5; private boolean iseate=false; public boolean isIseate() return iseate; public void setIseate(boolean iseate) this.iseate = iseate; public int getLength() return length; public void setLength(int length) this.length = length; private int wid

18、th=8; public int getWidth() return width; public void setWidth(int width) this.width = width; public int getDirestion() return direstion; public void setDirestion(int direstion) this.direstion = direstion; public int getX() return x; public void setX(int x) this.x = x; public int getY() return y; public void setY(int y) this.y = y;/记录类public class Recorder private int count=0; public String recorder; public void cadd() count+; public int getcount() return count; public void filereader

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1