3.17

学习JAVA做的第一个控制台小游戏
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

因为要忙毕设和毕业论文,精力无法集中,导致游戏无法达到自己的预期效果


一、游戏介绍

我们这款游戏是一款文字控制台小游戏,背景是中国武侠风,玩家可以在游戏开始时,了解本游戏的背景故事,阅读完后可以输入玩家的角色名,选择自己想要加入的门派,在各自门派中可以学习该门派的独有技能,每个大地图都有一个门派,医管和修炼房,而其中的一个地图有怪物的小地图,玩家可以通过打怪获得经验和金币进行升级,最终打败最终BOSS来实现游戏通关。

二、功能实现

1.玩家类属性

代码如下(示例):

 public String name;//名字
    public String[] skill = new String[5];//技能
    public String profession = "散人";//职业门派
    public int money;//金钱
    public int experience;//经验值
    public int gradexcpiton;//当前等级经验最大值
    public int grade;//等级
    //四大基本属性
    public int HP;//血量
    public int allHP;//血量上限
    public int MP;//蓝量
    public int allMP;//蓝量上限
    public int PA;//物理攻击
    public int MA;//魔法攻击

2.角色门派初始属性

     //职业选择
    public void pfChoose(int i) {
        if (i == 1) {
            this.profession = "绝情谷";
//            System.out.println("您的门派为:" + this.profession);
        } else if (i == 2) {
            this.profession = "藏剑山庄";
//            System.out.println("您的门派为:" + this.profession);
        } else if (i == 3) {
            this.profession = "神龙岛";
//            System.out.println("您的门派为:" + this.profession);
        } else if (i == 4) {
            this.profession = "红花会";
//            System.out.println("您的门派为:" + this.profession);

        } else if (i == 5) {
            this.profession = "唐门";
//            System.out.println("您的门派为:" + this.profession);
        } else {
            System.out.println("该门派不存在,请重新输入");
            System.out.println(0);
        }
    }
// 初始属性
    public void cssx() {
        if (this.profession == "绝情谷") {
            this.HP = 100;
            this.MP = 50;
            this.PA = 20;
            this.MA = 50;
        }
        if (this.profession == "藏剑山庄") {
            this.HP = 100;
            this.MP = 50;
            this.PA = 55;
            this.MA = 40;
        }
        if (this.profession == "神龙岛") {
            this.HP = 100;
            this.MP = 50;
            this.PA = 40;
            this.MA = 40;

        }
        if (this.profession == "红花会") {
            this.HP = 100;
            this.MP = 50;
            this.PA = 45;
            this.MA = 35;
        }
        if (this.profession == "唐门") {
            this.HP = 100;
            this.MP = 50;
            this.PA = 15;
            this.MA = 40;
        }
        this.allHP = this.HP;
        this.allMP = this.MP;
    }

3.角色升级

代码如下(示例):

 public void gradeIn() {

        this.grade++;//等级增加
        this.experience = this.experience - this.gradexcpiton;//升级后余下经验
        this.gradexcpiton = this.grade * 10;//经验上限增加
        System.out.println("恭喜你升级了!");
        gradesdAdd();//升级后属性成长
    }

4.角色升级属性成长

代码如下(示例):

 //人物升级
    public void gradeIn() {

        this.grade++;//等级增加
        this.experience = this.experience - this.gradexcpiton;//升级后余下经验
        this.gradexcpiton = this.grade * 10;//经验上限增加
        System.out.println("恭喜你升级了!");
        gradesdAdd();//升级后属性成长
    }

    public void gradesdAdd() {
        if (this.profession == "绝情谷") {
            this.allHP = this.allHP + 10;
            this.allMP = this.allMP + 10;
            this.PA = this.PA + 2;
            this.MA = this.MA + 4;
        }
        if (this.profession == "藏剑山庄") {
            this.allHP = this.allHP + 20;
            this.allMP = this.allMP + 3;
            this.PA = this.PA + 4;
            this.MA = this.MA + 0;
        }
        if (this.profession == "神龙岛") {
            this.allHP = this.allHP + 10;
            this.allMP = this.allMP + 10;
            this.PA = this.PA + 3;
            this.MA = this.MA + 3;
//            System.out.println("您的1技能为:"+this.skill[0]);

        }
        if (this.profession == "红花会") {
            this.HP = this.HP + 8;
            this.MP = this.MP + 10;
            this.PA = this.PA + 2;
            this.MA = this.MA + 4;
        }
        if (this.profession == "唐门") {
            this.HP = this.HP + 8;
            this.MP = this.MP + 12;
            this.PA = this.PA + 2;
            this.MA = this.MA + 3;
        }
        this.HP = this.allHP;
        this.MP = this.allMP;
    }

5.修炼馆

代码如下(示例):

//练功房修炼
    Scanner scanner = new Scanner(System.in);
    public void xiulian(Player player) {

        System.out.println("你到了练功房,修炼一次消耗500金币,增加50经验值 是否进行修炼(true 1/false 0)");
        int s = scanner.nextInt();
        if (s == 1) {
            if (s == 1) {
                if (player.money >= 500) {
                    player.money=player.money - 500;
                   player.experience = player.experience + 50;

                    if (player.experience >= player.gradexcpiton) {
                        player.gradeIn();
                    }
                    if (player.experience >= player.gradexcpiton) {
                        player.gradeIn();
                    }

                } else {
                    System.out.println("您的金钱不足,不足以支付修炼费用");
                }
            }
        }
    }

6.医馆

代码如下(示例):

 //医馆
    public void doctors(Player player){
        System.out.println("你遇到了医师 是否需要服务 (true 1/false 0)");
        int s = scanner.nextInt();
        if (s == 1) {

            System.out.println("1、500金币治疗满血 2、200金币回复满蓝");
            System.out.println("请输入需要的操作");
            int x = scanner.nextInt();
            if (x == 1) {
                if (player.money >= 500) {
                    player.HP = player.allHP;
                    player.money = player.money - 500;
                } else {
                    System.out.println("您的金钱不足,不足以支付治疗费用");
                }
            } else {
                if (player.money >= 200) {
                    player.MP = player.allMP;
                    player.money = player.money - 200;
                } else {
                    System.out.println("您的金钱不足,不足以支付回蓝费用");
                }
            }
        }
    }

7.门派

代码如下(示例):
这里角色无论有没有金钱学习技能都会学会,因为我在调用显示技能的时候就把技能赋值进去了。我这里搞了一个对象来存应该就能解决这个问题了

 public void professionly(Player player){
            Skill skill=new Skill();
            System.out.println("你遇到了你的师傅 是否学习技能(true 1/false 0)");
            int s = scanner.nextInt();
            if (s == 1) {
                System.out.println("技能列表");
                System.out.println("0、"+skill.secondSkill(player));
//               System.out.println(skill.skill[1]);
                int x = scanner.nextInt();
                                   if(player.money>=3000) {
                                       if (x == 0) {
                                           player.money=player.money-3000;
                                           String a=skill.secondSkill(player);
                                           player.skill[1] = a;
                                           System.out.println("你习得技能:" + player.skill[1]);
                                       }
                                   }
                                   else
                                       System.out.println("您的金钱不足以学习该技能");
            }
        }

8.游戏演示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


总结

通过两周的学习,期间了解了JAVA的特性,封装、继承、多态,在本次项目中老师要求我们尽量的使用面向对象的思想来做,但是做的时候却还是使用面向过程的思想进行的编码,虽然进行了封装,但是封装的过于功能多元化,继承方面就是为了继承某个属性而去继承,至于多态更是没有用到。总之,学习JAVA还是得先有面向对象的思想,思维不转变,JAVA的运用将会很难,学习效率也会不高。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
libsvm-3.17是一个机器学习库,用于支持向量机(Support Vector Machines)的训练和预测。你可以通过在libsvm的网站上下载libsvm-3.12.zip文件,并将其解压到任意目录下,最好是放在MATLAB工具箱中,比如D:\program files (x86)\MATLAB\R2014a\toolbox\libsvm-3.22下。另外,你还需要安装相关软件,包括python3.2、libsvm3.17和gnuplot,并将其分别安装在指定的目录下,例如python3.2安装在d:/Python32,libsvm3.17安装在D:\libsvm-3.17,gnuplot安装在D:\gnuplot。 要在Windows上使用libsvm-3.17,你需要在命令窗口中输入"make"命令。虽然可能会出现找不到svmtrain.exp和svmpredict.exp的提示,但只要在libsvm/matlab目录下生成了四个文件(libsvmread.mexw32、libsvmwrite.mexw32、svmtrain.mexw32和svmpredict.mexw32),你就可以将这四个文件复制到..MATLAB\R2014a\toolbox\libsvm-3.22\windows目录下,替换原来的文件。 总结起来,libsvm-3.17是一个机器学习库,用于支持向量机的训练和预测。你需要下载并解压libsvm-3.12.zip文件,安装相关软件,并复制生成的四个文件到指定目录中,以便在MATLAB中使用libsvm-3.17。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [MATLAB R2014a 装 libsvm-3.17](https://blog.csdn.net/abc1942227359/article/details/77989988)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [python3.2+libsvm3.17的配置](https://blog.csdn.net/laoyaotask/article/details/22654989)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值