![Java名字打架小游戏代码_第1页](http://file4.renrendoc.com/view14/M07/20/29/wKhkGWZfvueANEqrAAC5dBVzkwA057.jpg)
![Java名字打架小游戏代码_第2页](http://file4.renrendoc.com/view14/M07/20/29/wKhkGWZfvueANEqrAAC5dBVzkwA0572.jpg)
![Java名字打架小游戏代码_第3页](http://file4.renrendoc.com/view14/M07/20/29/wKhkGWZfvueANEqrAAC5dBVzkwA0573.jpg)
![Java名字打架小游戏代码_第4页](http://file4.renrendoc.com/view14/M07/20/29/wKhkGWZfvueANEqrAAC5dBVzkwA0574.jpg)
![Java名字打架小游戏代码_第5页](http://file4.renrendoc.com/view14/M07/20/29/wKhkGWZfvueANEqrAAC5dBVzkwA0575.jpg)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Java名字打架小游戏代码一、截图如下:1、初始界面:游戏中界面:游戏结束界面:程序代码如下:importjava.awt.*;importjava.awt.event.*;classGameextendsFrameimplementsActionListener{ Labell1,l2,label0,label1,label2,label3,label4,label5,label6,label7; TextFieldtext1,text2,text3,text4,text5,text6; Buttonbutton,button1,button2; Panelp1,p2,p3,p4; TextAreaarea; Menumenu; MenuBarmenubar; MenuItemitem1,item2; intHP,gongji,fangyv; intcount1=0,count2=0,count3=0,count4=0; Threadthread1; Game(Strings) { super(s); thread1=newThread(); label0=newLabel("初始血量在2000-3000之间随机产生!"); l1=newLabel("姓名1",Label.CENTER); l2=newLabel("姓名2",Label.CENTER); label1=newLabel("姓名1",Label.CENTER); label2=newLabel("姓名2",Label.CENTER); label3=newLabel("属性1",Label.CENTER); label4=newLabel("属性2",Label.CENTER); label5=newLabel("PK状态",Label.CENTER); label6=newLabel("被治疗次数:"+count1+"被攻击次数:"+count2); label7=newLabel("被治疗次数:"+count3+"被攻击次数:"+count4); p1=newPanel(); p2=newPanel(); p3=newPanel(); p4=newPanel(); area=newTextArea(10,30); text1=newTextField(5); text2=newTextField(5); text3=newTextField(34); text4=newTextField(34); text5=newTextField(27); text6=newTextField(27); button=newButton("确定"); button1=newButton("重新输入"); button2=newButton("退出"); thread1.start(); add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); p1.add(label0); p2.add(label1); p2.add(text1); p2.add(button); p2.add(label2); p2.add(text2); p2.add(label3); p2.add(text3); p2.add(label4); p2.add(text4); p2.add(label5); p2.add(p3); p2.add(label6); p2.add(p4); p2.add(label7); p2.add(area); p2.add(button1); p2.add(button2); p3.add(l1); p3.add(text5); p4.add(l2); p4.add(text6); l1.setLocation(0,0); text5.setLocation(20,0); area.setEditable(false); text3.setEditable(false); text4.setEditable(false); text5.setEditable(false); text6.setEditable(false); button.setBackground(Color.LIGHT_GRAY); button1.setBackground(Color.LIGHT_GRAY); button2.setBackground(Color.LIGHT_GRAY); label0.setBackground(Color.orange); label3.setBackground(Color.cyan); label4.setBackground(Color.cyan); label5.setBackground(Color.cyan); button.addActionListener(this); button1.addActionListener(this); button2.addActionListener(this); menu=newMenu("菜单"); item1=newMenuItem("打开"); item2=newMenuItem("退出"); p2.setBackground(Color.pink); p1.setBackground(Color.orange); menubar=newMenuBar(); menu.add(item1); menu.addSeparator(); menu.add(item2); menubar.add(menu); setMenuBar(menubar); item2.addActionListener(this); area.setBackground(Color.yellow); addWindowListener(newWindowAdapter() { publicvoidwindowClosing(WindowEvente) { System.exit(0); } }); setBounds(500,100,285,590); setResizable(false);//设置窗口不可调整大小 setVisible(true); validate(); } publicvoidactionPerformed(ActionEvente) { if(e.getSource()==item2||e.getSource()==button2) System.exit(0); elseif(e.getSource()==button) { Stringname1=text1.getText(); Stringname2=text2.getText(); NPCCnpc1=newNPCC(name1); NPCCnpc2=newNPCC(name2); npc1.shuxing(); npc2.shuxing(); l1.setText(name1); l2.setText(name2); inth1,h2; h1=npc1.HP; h2=npc2.HP; text3.setText(name1+":HP:"+npc1.HP+"攻击:"+npc1.gongji+"防御:"+npc1.fangyv); text4.setText(name2+":HP:"+npc2.HP+"攻击:"+npc2.gongji+"防御:"+npc2.fangyv); inti=0; while(npc1.HP>0&&npc2.HP>0) { if(i%2==0) { Strings1=npc1.damage(npc2.gongji); if(npc1.HPP!=0) { count1++; } else { count2++; } label6.setText("被治疗次数:"+count1+"被攻击次数:"+count2); Strings=s1; npc1.HP=npc1.HP+npc1.HPP+npc1.fangyv-npc1.hurt; if(npc1.HP>h1) { area.append(name1+s+'\n'); text5.setText(name1+s); try { thread1.sleep(1000); } catch(InterruptedExceptionee){} npc1.HP=h1; s1="血量已达最大值!!"; } if(npc1.HP<0) { npc1.HP=0; } text3.setText(name1+":HP:"+npc1.HP+"攻击:"+npc1.gongji+"防御:"+npc1.fangyv); text5.setText(name1+s1); area.append(name1+s1+'\n'); area.append(name1+"剩余生命值:"+npc1.HP+'\n'); } else { Strings2=npc2.damage(npc1.gongji); if(npc2.HPP!=0) { count3++; } else { count4++; } label7.setText("被治疗次数:"+count3+"被攻击次数:"+count4); Strings=s2; npc2.HP=npc2.HP+npc2.HPP+npc2.fangyv-npc2.hurt; if(npc2.HP>h2) { text6.setText(name2+s); area.append(name2+s+'\n'); try { thread1.sleep(1000); } catch(InterruptedExceptionee){} npc2.HP=h2; s2="血量已达最大值!!"; } if(npc2.HP<0) { npc2.HP=0; } text4.setText(name2+":HP:"+npc2.HP+"攻击:"+npc2.gongji+"防御:"+npc2.fangyv); text6.setText(name2+s2); area.append(name2+s2+'\n'); area.append(name2+"剩余生命值:"+npc2.HP+'\n'); } try { thread1.sleep(1000); } catch(InterruptedExceptionee){} i++; } if(npc1.HP<=0) { text5.setText(name1+"挂了!!!\n"); text6.setText(name1+"挂了!!!\n"); area.append(name1+"挂了!!!\n"); } elseif(npc2.HP<=0) { text5.setText(name2+"挂了!!!\n"); text6.setText(name2+"挂了!!!\n"); area.append(name2+"挂了!!!\n"); } } elseif(e.getSource()==button1) { text1.setText(null); text2.setText(null); text3.setText(null); text4.setText(null); text5.setText(null); text6.setText(null); area.setText(null); label6.setText("被治疗次数:"+0+"被攻击次数:"+0); label7.setText("被治疗次数:"+0+"被攻击次数:"+0); l1.setText("姓名1"); l2.setText("姓名2"); } }}classNPCC{ Stringname,s; intHP,gongji,fangyv; intHPP=0; inthurt=0; NPCC(Stringname) { =name; } publicvoidshuxing() { HP=(int)(Math.random()*1000)+2000; gongji=(int)(Math.random()*150)+80; fangyv=(int)(Math.random()*30)+50; } publicStringdamage(intgongji) { inta=(int)(Math.random()*10); switch(a) { case1: s="受到普通攻击"; hurt=gongji; HPP=0; break;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《贷款业务管理》课件
- 《电子产品制造工艺》课件
- 《RA的血液净化》课件
- 《阿里物流简介》课件
- 《华为组织结构图》课件
- 《MBO与股权激励》课件
- 2025至2031年中国伞尖行业投资前景及策略咨询研究报告
- 2025至2030年中国直柄风动砂轮机数据监测研究报告
- 【语文】《烛之武退秦师》课件+2024-2025学年统编版高一语文必修下册
- 《“红领巾”真好教学课件》
- 2024中国糖果、巧克力制造市场前景及投资研究报告
- 2025年纪检办公室工作计划范文
- 2024年保险公司柜员年终工作总结
- 2025年南瑞集团招聘笔试参考题库含答案解析
- 七年级上学期历史期末考试模拟卷02(原卷版)
- 桥梁建设施工组织设计方案
- 2024年思想道德与政治考试题库 (单选、多选)
- (新版)中国动态血压监测基层应用指南(2024年)
- 2025年上半年上饶市上饶县事业单位招考(139名)易考易错模拟试题(共500题)试卷后附参考答案
- 2024托盘行业市场趋势分析报告
- GB/T 44892-2024保险业车型识别编码规则
评论
0/150
提交评论