); int b = color.nextInt(256); g.setColor(new Color(r, g1, b)); g.fillOval(color.nextInt(750), color.nextInt(530), 5, 5); } }*/ public void paintScore(Graphics g){//画字符相关的 g.setColor(Color.lightGray); Font f = getFont(); Font font = new Font(f.getName(),Font.BOLD,0x1e); int x = 130; int y = 275; String str = "SCORE:"+this.score; g.setFont(font); g.drawString(str, x, y); str="TANK:"+enemyTank.length ; x+=170; g.drawString(str, x, y); x+=140; str = "[Q]Quit!"; if(gameOver){ str = "[Y]Start!"; } g.drawString(str, x, y); } public void paintWall(Graphics g){//画中间的柱子 g.setColor(Color.LIGHT_GRAY); g.fill3DRect(WIDTH/2-45,150 , 40, HEIGHT-300, false); g.fill3DRect(130,HEIGHT/2-20 , WIDTH-300, 40, false); } /**画自己坦克子弹,同时判断子弹有没有击中敌人*/ public void paintShoot(Graphics g){ ShootDispeal(); for (int i = 0; i < Shoot.myShoot.length; i+=4) { if(Shoot.myShoot[i]==0&&Shoot.myShoot[i+1]==0){ continue; } g.setColor(Color.RED); g.fillOval(Shoot.myShoot[i], Shoot.myShoot[i+1], 10, 10); int x = Shoot.myShoot[i]; int y = Shoot.myShoot[i+1]; for (int j = 0; j < enemyTank.length; j++) { int ex = enemyTank[j].getX(); int ey = enemyTank[j].getY(); if(x>ex&&xey&&y score+=1; level(); enemyTank[j].s=false;//坦克死亡,线程关闭 enemyTank[j]=nextTank(); enemyTank[j].start(); Shoot.myShoot[i]=0;Shoot.myShoot[i+1]=0;//子弹消失 Shoot.myShoot[i+2]=0;Shoot.myShoot[i+3]=0; shootNum++; shootNum1++; } } Shoot.myShoot[i]+=Shoot.myShoot[i+2]; Shoot.myShoot[i+1]+=Shoot.myShoot[i+3]; } } /**画敌人发出的子弹,同时判断是否击中了我的坦克*/ public void paintEemyShoot(Graphics g){ ShootDispeal(); for (int i = 0; i < Shoot.enemyShoot.length; i+=4) { if(Shoot.enemyShoot[i]==0&&Shoot.enemyShoot[i+1]==0){ continue; } g.setColor(Color.blue); g.fillOval(Shoot.enemyShoot[i], Shoot.enemyShoot[i+1], 10, 10); int x = Shoot.enemyShoot[i]; int y = Shoot.enemyShoot[i+1]; int mx = myTank[0].getX(); int my = myTank[0].getY(); int mx1 = myTank[1].getX(); int my1 = myTank[1].getY(); if(x>mx&&xmy&&y myTank[0].setLive(false); checkGameOver(); } if(x>mx1&&xmy1&&y myTank[1].setLive(false); checkGameOver(); } Shoot.enemyShoot[i]+=Shoot.enemyShoot[i+2];//根据步伐,改变子弹的坐标 Shoot.enemyShoot[i+1]+=Shoot.enemyShoot[i+3]; } } /**画坦克*/ public void paintTank(int x,int y,Graphics g,int direct,int who,boolean isLive){ Color color = null;//设置颜色 if(isLive){ if(who==0){//我的坦克 color=Color.green; }else if(who==-1){ color=Color.yellow; }else if(who==1){//1,2,3敌人的坦克,3种颜色 color=Color.red; }else if(who==2){ color=Color.magenta; }else if(who==3){ color=Color.CYAN; } switch(direct){//根据方向画出不同方向的坦克 case 1:g.setColor(color);paintUpTank(x,y,g);break; case 2:g.setColor(color);paintRightTank(x,y,g);break; case 3:g.setColor(color);paintDownTank(x,y,g);break; |