坦克大战—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);
}
标签:String,18,MyUtil,day,MODIFIY,NAMES,大战,public,name 来源: https://blog.csdn.net/qq_44856793/article/details/113556334