【vb精品源码栏目提醒】:网学会员,鉴于大家对vb精品源码十分关注,论文会员在此为大家搜集整理了“Java名字打架小游戏代码 - 其它资料”一文,供大家参考学习!
Java 名字打架小游戏代码一、截图如下:1、初始界面:2、游戏中界面:3、游戏结束界面:二、程序代码如下:import java.awt.import java.awt.event.class Game extends Frame implements ActionListener Labell1l2label0label1label2label3label4label5label6label7 TextField text1text2text3text4text5text6 Button buttonbutton1button2 Panel p1p2p3p4TextArea areaMenu menuMenuBar menubarMenuItem item1item2int HPgongjifangyvint count10count20count30count40Thread thread1GameString s supers thread1new Thread label0new Label初始血量在2000-3000之间随机产生! l1new Label姓名1Label.CENTER l2new Label姓名2Label.CENTER label1new Label姓名1Label.CENTER label2new Label姓名2Label.CENTER label3new Label属性1Label.CENTER label4new Label属性2Label.CENTER label5new LabelPK状态Label.CENTER label6new Label被治疗次数:count1 被攻击次数:count2 label7new Label被治疗次数:count3 被攻击次数:count4 p1new Panel p2new Panel p3new Panel p4new Panel areanew TextArea1030 text1new TextField5 text2new TextField5 text3new TextField34 text4new TextField34 text5new TextField27 text6new TextField27 buttonnew Button确定 button1new Button重新输入 button2new Button退出 thread1.start addp1BorderLayout.NORTH addp2BorderLayout.CENTER p1.addlabel0 p2.addlabel1 p2.addtext1 p2.addbutton p2.addlabel2p2.addtext2p2.addlabel3p2.addtext3p2.addlabel4p2.addtext4p2.addlabel5p2.addp3p2.addlabel6p2.addp4p2.addlabel7p2.addareap2.addbutton1p2.addbutton2p3.addl1p3.addtext5p4.addl2p4.addtext6l1.setLocation0 0text5.setLocation200area.setEditablefalsetext3.setEditablefalsetext4.setEditablefalsetext5.setEditablefalsetext6.setEditablefalsebutton.setBackgroundColor.LIGHT_GRAYbutton1.setBackgroundColor.LIGHT_GRAYbutton2.setBackgroundColor.LIGHT_GRAYlabel0.setBackgroundColor.orangelabel3.setBackgroundColor.cyanlabel4.setBackgroundColor.cyanlabel5.setBackgroundColor.cyanbutton.addActionListenerthisbutton1.addActionListenerthisbutton2.addActionListenerthismenunew Menu菜单item1new MenuItem打开item2new MenuItem退出p2.setBackgroundColor.pinkp1.setBackgroundColor.orangemenubarnew MenuBarmenu.additem1menu.addSeparatormenu.additem2menubar.addmenu setMenuBarmenubar item2.addActionListenerthis area.setBackgroundColor.yellow addWindowListenernew WindowAdapter public void windowClosingWindowEvent e System.exit0 setBounds500100285590 setResizablefalse//设置窗口不可调整大小 setVisibletrue validate public void actionPerformedActionEvent e ife.getSourceitem2 e.getSourcebutton2 System.exit0 else ife.getSourcebutton String name1text1.getText String name2text2.getText NPCC npc1new NPCCname1 NPCC npc2new NPCCname2 npc1.shuxing npc2.shuxing l1.setTextname1 l2.setTextname2 int h1h2 h1npc1.HP h2npc2.HP text3.setTextname1: HP:npc1.HP 攻击:npc1.gongji防御:npc1.fangyv text4.setTextname2: HP:npc2.HP 攻击:npc2.gongji防御:npc2.fangyv int i0 whilenpc1.HP0 npc2.HP0 if i20 String s1npc1.damagenpc2.gongji ifnpc1.HPP0 count1 else count2 label6.setText 被 治 疗 次 数 :count1 被攻击次数:count2 String ss1 npc1.HPnpc1.HPnpc1.HPPnpc1.fangyv-npc1.hurt ifnpc1.HPh1 area.appendname1sn text5.setTextname1s try thread1.sleep1000 catchInterruptedException ee npc1.HPh1 s1血量已达最大值!! ifnpc1.HPh2 text6.setTextname2s area.appendname2sn try thread1.sleep1000 catchInterruptedException ee npc2.HPh2 s2血量已达最大值!! ifnpc2.HP