随机之魂

来源:互联网 发布:态度潮人老杨淘宝店 编辑:程序博客网 时间:2024/05/17 07:38

随机之魂
我们两个就想做游戏,做游戏!!!
然后我们就做了一个最简单的游戏,很远古的那种,一开始只加了攻击和命中率。

代码:这里写图片描述
这里写代码片

public void actionPerformed(java.awt.event.ActionEvent e) {`                Label.setIcon(new ImageIcon("D:\\新建文件夹\\3.gif"));                Random rm =new Random();                mingzhong=rm.nextInt(100)+1;                if(mingzhong>50){                hexueliang-=yougongji;                text1.setText("你攻击了对方。\n对方血量-"+yougongji);                texthe.setText("敌人的血量:"+hexueliang+"\n敌人的攻击:"+hegongji);                if(hexueliang<=0){                    JOptionPane.showMessageDialog(null, "你怼死了敌人", "获胜!", JOptionPane.ERROR_MESSAGE);                    hexueliang=rm.nextInt(1000)+1;                    hegongji=rm.nextInt(100)+1;                    texthe.setText("敌人的血量:"+hexueliang+"\n敌人的攻击:"+hegongji);                    text1.setText("");                    direnshuliang+=1;                    he.setText("敌人"+direnshuliang);                    return;                }                }                else                    text1.setText("你没有命中。");                mingzhong=rm.nextInt(100)+1;                if(mingzhong>50){                youxueliang-=hegongji;                text1.append("\n对方攻击了你。\n你的血量-"+hegongji);                textyou.setText("你的血量"+youxueliang+"\n你的攻击"+yougongji);                if(youxueliang<=0){                     int res=JOptionPane.showConfirmDialog(null, "你已经死亡", "是否继续", JOptionPane.YES_NO_OPTION);                     if(res==JOptionPane.YES_OPTION){                         youxueliang=rm.nextInt(1000)+1;                        yougongji=rm.nextInt(100)+1;                        textyou.setText("你的血量"+youxueliang+"\n你的攻击"+yougongji); //点击“是”后执行这个代码块                        hexueliang=rm.nextInt(1000)+1;                        hegongji=rm.nextInt(100)+1;                        texthe.setText("敌人的血量:"+hexueliang+"\n敌人的攻击:"+hegongji);                        text1.setText("");  //点击“是”后执行这个代码块                    }else{                                System.exit(0);                           }}                else                    text1.append("\n对方没有命中。");            }

然后自己和敌人的血量和攻击力做了个随机:

然后我们加上了可以攻击不同部位的按钮,打不同地方命中率是不一样的
(自杀就不用多说了)

一开始的时候敌人打死一个就完了,之后我们加上了敌人的数量显示,可以一直打,每打死一个数量加1。

然后我们加上了死亡和获胜时的弹出窗口。

因为不能回血,所以不能打很久,于是我们做了打过3个人就能重新刷新血量或攻击力的设定。
if(direnshuliang%3==0){
Object[] options = {“随机血量”,”随机攻击”,”取消随机”};

// 定制可供选择按钮

                int response=JOptionPane.showOptionDialog(null, "你升级了","你怼死了3个敌人",JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);                if(response==0) {                       youxueliang=rm.nextInt(1000)+1;                       textyou.setText("你的血量"+youxueliang+"\n你的攻击"+yougongji);                } else if(response==1) {            yougongji=rm.nextInt(100)+1;                } else if(response==2) {                               JOptionPane.showMessageDialog(null,"取消随机","消息",JOptionPane.INFORMATION_MESSAGE);                             }

然后白雨童觉得太难看了,在界面上加了图片和音乐。

我们不想做SQL,于是最后做了保存和读取(在txt文件里)
保存:

读取:

(读取没做出来!!!!!我们真的努力做了!!!!!)

这个游戏我们是准备一直更新的,以后还要加上:读取、敌人AI、随机事件、作弊代码,还有其他的等放上了steam再更新。