坦克大战—day 18

给坦克添加名字

在MyUtil类中:

private static final String[] NAMES = {
            "行人","乐园","花草","人才","左手","目的","课文","优点","年代","灰尘",
            "沙子","小说","儿女","难题","明星","本子","彩色","水珠","路灯","把握",
            "房屋","心愿","左边","新闻","早点","鸭子",
            "市场","雨点","细雨","书房","毛巾","画家","元旦","绿豆","本领","起点",
            "青菜","土豆","总结","礼貌","右边",
            "老虎","老鼠","猴子","树懒","斑马","小狗","狐狸","狗熊","黑熊",
            "大象","豹子","麝牛","狮子","熊猫","疣猪","羚羊","驯鹿","考拉",
            "犀牛","猞猁","猩猩","海牛","水獭","海豚","海象","刺猬","袋鼠",
            "犰狳","河马","海豹","海狮","蝙蝠","白虎","狸猫","水牛","山羊",
            "绵羊","牦牛","猿猴","松鼠","野猪","豪猪","麋鹿","花豹","野狼",
            "灰狼","蜂猴","熊猴","叶猴","紫貂","貂熊","熊狸","云豹","雪豹",
            "黑麂","野马","鼷鹿","坡鹿","豚鹿","野牛","藏羚","河狸","驼鹿",
            "黄羊","鬣羚","斑羚","岩羊","盘羊","雪兔"
    };

    private static final String[] MODIFIY = {
            "可爱","傻傻","萌萌","羞羞","笨笨","呆呆","美丽","聪明","伶俐","狡猾",
            "胖乎乎","粉嫩嫩","白胖胖","漂亮","可爱","聪明","懂事","乖巧","淘气",
            "淘气","顽劣","调皮","顽皮","天真","可爱","无邪","单纯","纯洁","无暇",
            "纯真","稚气","温润","好奇",
    };
    public static final String getRandomName(){
        return MODIFIY[getRandomNumber(0,MODIFIY.length)] + "的" +
                NAMES[getRandomNumber(0,NAMES.length)];
    }

在tank类中:

private String name;



    public Tank(int x,int y,int dir){
        this.x=x;
        this.y=y;
        this.dir=dir;
        color= MyUtil.getRandomColor();
        name = MyUtil.getRandomName();
    }

    public void draw(Graphics g)
    {

        logic();
        drawImgTank(g);
        //drawTank(g);
        drawBullet(g);
        drawName(g);
    }

    public  void drawName(Graphics g)
    {
        g.setColor(color);
        g.setFont(Constant.SMALL_FONT);
        g.drawString(name,x-RADIUS,y-40);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值