宝可梦小游戏_Java_控制端——总结

宝可梦&伏魔录 小游戏_Java_控制端:小总结

前言

此文档主要是作为Java初学者的第一次小项目,虽然项目还不够完善,但是想在这里做一下总结。也顺便梳理以下最近的学习,对自己整个的学习自我认知一下。
可能现在作者水平有限,但是确实初学者当下比较真实的想法与认知,期望各位创客能多加以指点。


一、简述

宝可梦项目是在还不是特别了解面向对象思想的时候,编写的项目。
但是,在此次项目之后,又通过面向对象的思想学习编写了伏魔录小游戏。
本文主要是通过开发两次项目的总结与经验做对比。比对出相应的问题与应该改进的地方。

二、宝可梦项目

1.设计思想

玩家首先获得一个宝可梦,有一定自身的属性和金钱;之后通过去不同地图从而进行商品的交易和打怪升级(其中也包含捕捉新的宝可梦等基本技能)。
总而言之,就是一个类似于宝可梦的超简化版小游戏 (控制台输入输出)。

整个宝可梦项目结构
尽管宝可梦版本还有很多不完善的地方,但是基本的功能运行是没有问题的。
整个项目的代码较为冗余,因此,只选择了Player类中的主要方法来展示,如下代码。

//遭遇野怪
    public void encounter(String monster) {
   
        int l = 0;
        if (monster.equals("boss")) {
   
            pokemons = boss;
            System.out.println("你嚣张的向道馆馆主发起了挑战。你大叫一声:呔! 你敢应战么?");
            System.out.println("道馆馆主抬起眼眸,轻蔑的瞟了你一眼:GO first!");
            System.out.println("你巴拉巴拉精灵袋:");
            showAll();//打印精灵
            System.out.println("————— @  ————");
            System.out.println(" || @@@@@ ||");
            System.out.println(" || @@@@@ ||");
            System.out.println(" ||_______||");
            System.out.println("你从袋子里选出来了一个小精灵:");
            int chioce = scanner.nextInt() - 1;
            show(chioce);//展示选择的宝可梦
            System.out.println("就是你了,宝可梦!||");
            pokemons.show();
            while (l == 0) {
   
                l = interfaces(monster, chioce);
            }
        } else if (monster.equals("monster")) {
   
            pokemons = createmonster();//调用
            System.out.println("野怪突然闪现,吓你一跳!");
            System.out.println("哎嘿?前面那是什么?难道是..." + pokemons.pokemonName + "?!!");
            System.out.println("这下可太好了,这种小怪小力的,用来训练最好了!@_@,去吧!宝可梦!");
            int chioce = scanner.nextInt() - 1;
            while (chioce < 0 || chioce > 3 || this.pokemon[chioce].pokemonName == null) {
   
                System.out.println("【NPC】你有吗?不,你没有!");
                chioce = scanner.nextInt() - 1;
            }
            while (!this.pokemon[chioce].pokemonStatus) {
   
                System.out.println("【NPC】你的宝可梦真实太菜了!竟然打不过?!你还有其他的宝可梦么?有就快上!别怂!");
                chioce = scanner.nextInt() - 1;
            }
            show(chioce);//我拥有的宝可梦
            pokemons.show();//小怪 宝可梦

            while (l == 0) {
   
                l = interfaces(monster, chioce);
            }
        }
    }

    public int interfaces(String monster, int chioces) {
   
        System.out.println("+--------------+");
        System.out.println("|1.战斗  2.物品|");
        System.out.println("|3.捕获  4.逃跑|");
        System.out.println("+--------------+");
        System.out.print("请选择你要进行的操作:");
        int choice = scanner.nextInt();
        while (choice > 4 || choice < 1) {
   
            System.out.println("不会吧,这么简单的操作都不会?重来重来!");
            choice = scanner.nextInt();
        }
        switch (choice) {
   
            //战斗
            case 1:
                return battle(chioces);
            //物品
            case 2:
                openpackage(monster);
                break;
            //捕获
            case 3:
                switch (capture()) {
   
                    //捕获失败直接结束
                    case -1:
                        return -1;
                    //精灵球不足或放弃捕捉
                    case 0:
                        interfaces(monster, choice);
                        break;
                    //捕捉成功
                    case 1:
                        for (int i = 0; i < 4; i++) {
   
                            if (this.pokemon[i] == null) {
   
                                this.pokemon[i] = pokemons;
                                break;
                            } else if (i == 3) {
   
                                System.out.println("你这瘦弱的身板只能携带四只,你要放弃你原有的宝可梦吗?(y/n)");
                                String z = scanner.next();
                                if (z.equals("y")) {
   
                                    //放弃
                                    System.out.println("好吧,你这个喜新厌旧的家伙");
                                    System.out.println("你要放弃哪一只?");
                                    System.out.println("1." + pokemon[0].pokemonName);
                                    System.out.println("2." + pokemon[1].pokemonName);
                                    System.out.println("3." + pokemon[2].pokemonName);
                                    System.out.println("4." + pokemon[3].pokemonName);
                                    int v = scanner.nextInt() - 1;
                                    pokemon[v] = pokemons;
                                } else {
   
                                    //不放弃
                                    System.out.println("看来你还是喜欢原来的,好吧那就这样吧");
                                }
                            }
                        }
                        return 2;
                }
                break;
            //逃跑
            case 4:
                System.out.println("你个s货,竟然跑了!");
                return -1;
        }
        return 0;
    }

    //战斗
    public int battle(int chioces) {
   
        int attack = 0;
        if (pokemons.pokemonStatus && pokemon[chioces].pokemonStatus) {
   
            System.out.println("+——宝可梦技能——+");
            System.out.println("+-------------------------------+");
            System.out.println("1." + this.pokemon[chioces].attackSkill1 + "  2." + this.pokemon[chioces].attackSkill2);
            System.out.println("3." + this.pokemon[chioces].attackSkill3 + "  4." + this.pokemon[chioces].specSkill);
            System.out.println("+-------------------------------+");
            System.out.print("【Select】选择你要进行的操作:");
            int choice1 = scanner.nextInt();
            switch (choice1) {
   
                case 1:
                    System.out.println("你使用了" + this.pokemon[chioces].attackSkill1);
                    attack = this.pokemon[chioces].attackSkill1Value + this
  • 9
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值