学完了面向对象,赵老师让做一个电子宠物,对于我这样的游戏迷来说,就忍不住做一个好玩的小游戏出来,于是,便运用目前所学的知识,经过了大概3到4天的时间,克服了重重困难,无数次修改,不断的修复BUG,不断的实现新的功能,不断的推翻重写,唉,终于做出了一个终极版。在此,记录一下。

package com.maya.chongwu;

import java.util.Scanner;

public class Main {
    public static String a;/*a,b,c,用来给创建的角色起名字。d用来决定角色的生肖*/
    public static String b;
    public static String c;
    public static int d;
    /*数组酷*/
    public static String[] qian = { "国服第一", "撒腿就跑", "万夫莫开", "一个打俩", "唧唧歪歪", "毁天灭地", "横扫幼儿园", "倒立吹牛", "你皮任你皮", "炸天炸地" };
    public static String[] qianzhui = { "哮天", "吞天", "吃屎", "六臂神", "九头多动", "中二", "瓜皮", "坑爹", "我是", "智障", "程序", "皮皮", "干炸脆皮",
            "求打死", "霸王" };
    public static String houzhui[] = { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
    public static void main(String[] args) {
        boolean lock = true;//
        boolean flag = true;//
        Pet pet=null;
        Scanner scanner = new Scanner(System.in);//用来为控制台输入创建对象
        do {
            /*用来控制只运行一次*/
            if (lock) {
                
            
                
                System.out.println("正在为你随机生成宠物类型...");
                try {
                    Thread.sleep(2000);//休眠2秒
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
                a=qian[(int) Math.floor(Math.random() * 10)];
                b=qianzhui[(int) Math.floor(Math.random() * 15)];
                d=(int)Math.floor((Math.random() * 12));
                c=houzhui[d];
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
                System.out.println( a+ b+ c);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
                System.out.println("输入宠物的姓名和性别, 用逗号隔开...");
                String info = scanner.nextLine();//输入的内容
                String[] _info = info.split(",");
                if(_info.length!=2) {
                    System.out.println("信息录入出错 ! 程序停止");
                    System.exit(0);
                } else {
                    if (d==0) {
                        pet = new Shu(_info[0], _info[1]);
                    } 
                    else if (d==1) {
                        pet = new Niu(_info[0], _info[1]);
                    }
                    else if (d==2) {
                        pet = new Hu(_info[0], _info[1]);
                    }
                    else if (d==3) {
                        pet = new Tu(_info[0], _info[1]);
                    }
                    else if (d==4) {
                        pet = new Long(_info[0], _info[1]);
                    }
                    else if (d==5) {
                        pet = new She(_info[0], _info[1]);
                    }
                    else if (d==6) {
                        pet = new Ma(_info[0], _info[1]);
                    }
                    else if (d==7) {
                        pet = new Yang(_info[0], _info[1]);
                    }
                    else if (d==8) {
                        pet = new Hou(_info[0], _info[1]);
                    }
                    else if (d==9) {
                        pet = new Ji(_info[0], _info[1]);
                    }
                    else if (d==10) {
                        pet = new Gou(_info[0], _info[1]);
                    }
                    else if (d==11) {
                        pet = new Zhu(_info[0], _info[1]);
                    }
                }
                pet.attribute();//随机属性
                pet.sex();//性别影响属性
            
                
                lock = false;
                pet.printInfo();//打印信息
                
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                
                e.printStackTrace();
            }
            System.out.println("选择要进行的操作:1--打印宠物信息, 2--吃饱了才能打得过, 3--吃颗草再战, 4--心情好才能暴击, 5--竞技场,6--退出");
            String opera = scanner.nextLine();
            if ("1".equals(opera)) {
                pet.printInfo();
            } else if ("2".equals(opera)) {
                pet.eatFood();
            } else if ("3".equals(opera)) {
                pet.eatMidical();
            } else if ("4".equals(opera)) {
                pet.play();
            }else if ("5".equals(opera)) {
                pet.fight(); 
            } 
            else if ("6".equals(opera)) {
                System.out.println(pet.getName() + "说: 好困啊, 回去睡觉觉了...");
                System.exit(0);
                flag = false;
            }
            
        } while (flag);
        scanner.close();//释放那个啥
    }
}

 

posted on 2017-05-23 23:13  缘来狠狂  阅读(180)  评论(0编辑  收藏  举报