用JAVA编写一个小程序,不限类型好玩点的。

用JAVA编写一个小程序,不限类型好玩点的。,第1张

控制台小游戏 class YZDEL\r\n{\r\n public static void main(String[] args)\r\n {\r\njava.util.Random Shiji = new java.util.Random()\r\n java.util.Scanner Shuru = new java.util.Scanner(System.in)\r\n java.util.Scanner Nandu = new java.util.Scanner(System.in)\r\n int YingxHP = 20\r\n int YingxMP = 0\r\n int MogHP = 20\r\n int MogMP = 0\r\n int MogDo = 0\r\n int fangyu = 0\r\n System.out.println("┏━━━━_┏━━┣┣┓ _ ┓┏━┳━┳┓┓━┓ ")\r\n System.out.println("┏┣━━━┓┏━━┣┣┓ ┃┏ ┃ ┃┓┃ _ ")\r\n System.out.println("┣┣━━━┫_━━┻__ ┃_┓┃ ┃_┏━┣━━┓")\r\n System.out.println("┣┣━━━┫┏━━━━┓_━━┣━┛┗━┻━┻┛┃┃")\r\n System.out.println("┏┣━━━┓┣━━━━┫ ┃┃┃┗__┃┃┣━_")\r\n System.out.println(" ┛┗_┗━━━━_┗___━━┛┛┗━__━┛")\r\n System.out.println()\r\n System.out.println(" 作者:天狐空幻")\r\n System.out.println()\r\n System.out.println("说明:勇者的 *** 作方式为以下所示:")\r\n System.out.println(" 使用攻击需消耗1MP 伤害1HP")\r\n System.out.println(" 使用蓄力可增加1MP 伤害0HP")\r\n System.out.println(" 使用躲闪需消耗0MP 伤害0HP 躲避攻击")\r\n System.out.println(" 使用重击需消耗3MP 伤害2HP 防御无效")\r\n System.out.println(" 恶龙攻击力高, 注意防御是取胜的关键")\r\n System.out.println(" 恶龙MP达到4时可能会放出火焰无法躲避")\r\n System.out.println(" 准备说明完毕,那么让我们来挑战恶龙吧!")\r\n System.out.println("==================================")\r\n //难度选择\r\n System.out.println("请选择难度")\r\n System.out.println("1.娱乐 2.挑战 3.噩梦")\r\n int ND = Nandu.nextInt()\r\n System.out.println("==================================")\r\n while(true) \r\n { \r\n //HP,MP的显示 \r\n System.out.print("勇者: ")\r\n System.out.print(" HP ")\r\n for(int x=YingxHPx>0x--) System.out.print("*")\r\n System.out.print(" "+YingxHP)\r\n System.out.println()\r\n System.out.print(" ")\r\n System.out.print(" MP ")\r\n for(int x=YingxMPx>0x--) System.out.print("*")\r\n System.out.print(" "+YingxMP)\r\n System.out.println()\r\n System.out.print("恶龙: ")\r\n System.out.print(" HP ")\r\n for(int y=MogHPy>0y--) System.out.print("*")\r\n System.out.print(" "+MogHP)\r\n System.out.println()\r\n System.out.print(" ")\r\n System.out.print(" MP ")\r\n for(int y=MogMPy>0y--) System.out.print("*")\r\n System.out.print(" "+MogMP)\r\n System.out.println()\r\n System.out.println("==================================")\r\n //胜利判定 \r\n if(YingxHP2&&MogMP>2) MogDo = 2\r\n else if(MogMP0) MogDo=2 \r\n if(Do==2&&MogMP==0) MogDo=0\r\n if(Do==3&&MogMP=4) MogDo=3}//变态判定。。 \r\n //战斗分析\r\n //防御 \r\n if(Do==3) {fangyu=1System.out.println("你灵巧的躲避攻击!")}\r\nif(MogDo==1) {fangyu=1System.out.println("恶龙进行防御!")}\r\n //角色判定 \r\n if(Do==1&&YingxMP==0) {System.out.println("MP不足!")}\r\n if(Do==1&&YingxMP>0) {\r\nif(fangyu==0) {MogHP=MogHP-1YingxMP=YingxMP-1System.out.println("你发动攻击!")}\r\nif(fangyu==1) {YingxMP=YingxMP-1System.out.println("你的攻击被格挡!")}} \r\n if(Do==2) {YingxMP=YingxMP+1System.out.println("你进行蓄力!")}\r\n if(Do==4&&YingxMP2) {MogHP=MogHP-2YingxMP=YingxMP-3System.out.println("你发动重击!")}\r\n if(Do>4) System.out.println("你不知所措...")\r\n //敌人判定 \r\n if(MogDo==2&&MogMP==0) {System.out.println("恶龙在发呆!")}\r\n if(MogDo==2&&MogMP>0) {\r\nif(fangyu==0) {YingxHP=YingxHP-2MogMP=MogMP-1System.out.println("恶龙发动攻击!")}\r\nif(fangyu==1) {MogMP=MogMP-1System.out.println("恶龙的攻击被躲开了!")}} \r\n if(MogDo==0) {MogMP=MogMP+1System.out.println("恶龙进行蓄力!")} \r\n if(MogDo==3&&MogMP3) {YingxHP=YingxHP-4MogMP=MogMP-4System.out.println("恶龙发动火焰吐吸!躲避不能!")} \r\n //结束 \r\n fangyu = 0\r\n MogDo = 0\r\n System.out.println("____________________")\r\n System.out.println()\r\n System.out.println("==================================") }\r\n }\r\n}

import java.util.Arrays

public class Array2 {

public static void main(String[] args) {

//声明一个名为myArray的数组,该数组有2行,每行列数不等,并为其分配内存空间

int[][] myArray = new int[2][]

myArray[0] = new int[5] //第一行有5个元素,并为其分配内存空间

myArray[1] = new int[10] //第二行有10个元素,并为其分配内存空间

for (int j = 0j <myArray[0].lengthj++)

//用1-10之间的随机整数给第一行元素赋值

myArray[0][j] = (int)(Math.random() * 10)

//用100-200之间的随机整数给第二行元素赋值

for (int j=0j <myArray[1].lengthj++)

myArray[1][j]=(int)(Math.random() * 100 + 100)

for (int i=0i <myArray.lengthi++){ //输出myArray数组各元素的值

for (int j=0j <myArray[i].lengthj++){

System.out.print(myArray[i][j]+" ")

}

System.out.println()

}

Arrays.sort(myArray[0]) //对第一行元素排序

Arrays.sort(myArray[1]) //对第二行元素排序

System.out.println("\n排序后的数组元素: ")

for (int i=0i<myArray.lengthi++){ //再次输出myArray数组各元素的值

for (int j=0j<myArray[i].lengthj++){

System.out.print(myArray[i][j]+" ")

}

System.out.println()

}

}

}

7 3 9 6 7

103 165 166 148 103 179 128 109 120 156

排序后的数组元素:

3 6 7 7 9

103 103 109 120 128 148 156 165 166 179

分类: 电脑/网络 >>程序设计 >>其他编程语言

问题描述:

我们修的汇编语言是JAVA,怎奈自己学术不精.现在此象高手请教.小程序是期末做课程设计用的.题目有日历记事本,学籍管理系统,计算器,画图程序.其他的也可以.现需要两个程序,谢谢大家!

解析:

import java.io.*

import java.util.Calendar

import java.awt.*

import java.awt.event.*

import javax.swing.*

public class NoteBook extends JFrame implements ActionListener,ItemListener,WindowListener,MouseListener{

Container c = this.getContentPane()

JMenuBar jmb = new JMenuBar()

JColorChooser jcc = new JColorChooser()

JMenu jm1 = new JMenu("文件(F)")

JMenu jm2 = new JMenu("编辑(E)")

JMenu jm3 = new JMenu("格式(O)")

JMenu jm4 = new JMenu("查看(V)")

JMenu jm5 = new JMenu("帮助(H)")

JMenuItem jmi1 = new JMenuItem("新建(N)")

JMenuItem jmi2 = new JMenuItem("打开(O)")

JMenuItem jmi3 = new JMenuItem("保存(S)")

JMenuItem jmi4 = new JMenuItem("退出(X)")

JMenuItem jmi5 = new JMenuItem("撤消(U)")

JMenuItem jmi6 = new JMenuItem("复制(C)")

JMenuItem jmi7 = new JMenuItem("粘贴(P)")

JMenuItem jmi8 = new JMenuItem("剪切(T)")

JMenuItem jmi12 = new JMenuItem("日期和时间")

JMenuItem jmi9 = new JMenuItem("字体(E)")

JCheckBoxMenuItem jcbmi = new JCheckBoxMenuItem("自动换行(W)")

JMenuItem jmi10 = new JMenuItem("删除(S)")

JMenuItem jmi11 = new JMenuItem("背景颜色(H)")

JTextArea jta = new JTextArea(15,15)

JScrollPane jsp = new JScrollPane(jta)

PupolMenu pm = new Pupolmenu()

NoteBook(){

this.addWindowListener(this)

c.setLayout(new BorderLayout())

c.add(jmb,BorderLayout.NORTH)

this.setTitle("新建 文本文档")

jmb.add(jm1)

jm1.setMnemonic('f')

jm1.addActionListener(this)

jmb.add(jm2)

jm2.setMnemonic('e')

jmb.add(jm3)

jm3.setMnemonic('o')

jmb.add(jm4)

jm4.setMnemonic('v')

jmb.add(jm5)

jm5.setMnemonic('h')

jm1.add(jmi1)

jmi1.addActionListener(this)

jmi1.setAccelerator(KeyStroke.getKeyStroke('N',Event.CTRL_MASK,false))

jm1.addSeparator()

jm1.add(jmi2)

jmi2.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK,false))

jmi2.addActionListener(this)

jm1.addSeparator()

jm1.add(jmi3)

jmi3.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK,false))

jmi3.addActionListener(this)

jm1.addSeparator()

jm1.add(jmi4)

jmi1.setMnemonic('n')

jmi2.setMnemonic('o')

jmi3.setMnemonic('s')

jmi4.setMnemonic('x')

jmi4.addActionListener(this)

jm2.add(jmi5)

jm2.addSeparator()

jm2.add(jmi6)

jm2.addSeparator()

jm2.add(jmi7)

jm2.addSeparator()

jm2.add(jmi8)

jm2.add(jmi12)

jmi12.addActionListener(this)

jm3.add(jcbmi)

jcbmi.addItemListener(this)

jm3.addSeparator()

jm3.add(jmi9)

jm4.add(jmi10)

jmi10.addActionListener(this)

jm5.add(jmi11)

jmi11.addActionListener(this)

c.add(jsp)

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)

this.setSize(500,500)

this.setVisible(true)

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==jmi1){

jta.setText("")

this.setTitle("无标题 - 记事本")

}

if(e.getSource()==jmi2){

File f1

JFileChooser jfc1 = new JFileChooser()

int num1 = jfc1.showOpenDialog(this)

if(num1==JFileChooser.APPROVE_OPTION){

try{

f1 = jfc1.getSelectedFile()

this.setTitle(f1.getName())

FileReader fr = new FileReader(f1)

BufferedReader br = new BufferedReader(fr)

String str

while((str = br.readLine())!=null){

jta.setText(str)

}

fr.close()

br.close()

}catch(FileNotFoundException e1){

e1.printStackTrace()

}catch(IOException e2){

e2.printStackTrace()

}

}

}

if(e.getSource()==jmi3){

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

}

}

if(e.getSource()==jmi4){

int a = JOptionPane.showConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION)

if(a==1){

this.dispose()

}else if(a==0){

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

this.dispose()

}

}

}

if(e.getSource()==jmi12){

Calendar c1 =Calendar.getInstance()

int y = c1.get(Calendar.YEAR)

int m = c1.get(Calendar.MONTH)

int d = c1.get(Calendar.DATE)

int h = c1.get(Calendar.HOUR)

int m1 = c1.get(Calendar.MINUTE)

int m2 = m+1

jta.setText(y+"年"+m2+"月"+d+"日"+h+":"+m1)

}

if(e.getSource()==jmi11){

Color ccc = JColorChooser.showDialog(this,"color",Color.BLACK)

jta.setSelectedTextColor(ccc)

jta.setBackground(ccc)

}

if(e.getSource()==jmi10){

jta.replaceRange("",jta.getSelectionStart(),jta.getSelectionEnd())

}

}

public void itemStateChanged(ItemEvent e2){

if(e2.getItemSelectable()==jcbmi){

jta.setLineWrap(true)

}else

jta.setLineWrap(false)

}

public static void main(String[] args){

new NoteBook()

}

public void windowOpened(WindowEvent arg0) {

}

public void windowClosing(WindowEvent arg0) {

int a = JOptionPane.showConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION)

if(a==1){

this.dispose()

}else if(a==0){

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

}

if(a==2){

????/????????????????????????????????????????????????????????????????

}

}

}

public void windowClosed(WindowEvent arg0) {

}

public void windowIconified(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowDeiconified(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowActivated(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowDeactivated(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void mouseClicked(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mousePressed(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseExited(MouseEvent arg0) {

TODO Auto-generated method stub

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11229005.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存